VBA Error executing query with parameters

pbassett

Active Member
Joined
May 5, 2004
Messages
358
I get this VBA error when I try to execute a query with 3 parameters
"-2147217887: Multiple-step OLE DB operation generated errors"
It runs fine from Access and I have run many queries in VBA without an issue. I don't believe I have previously seen this error so hopefully someone can help.
The parameters are:
.Parameters.Append .CreateParameter("param1", adVarWChar, adParamInput, adChar, i)
.Parameters.Append .CreateParameter("param2", adDate, adParamInput, adChar, Me.StartDate)
.Parameters.Append .CreateParameter("param3", adDate, adParamInput, adChar, Me.EndDate)
For the parameters, i starts as 1 and the form contains the StartDate and EndDate date fields.
The query does a Group By:

SELECT Main.Category
FROM Main
WHERE (((Main.Type)=[Type: 1=Safety; 2 = Maintenance]) AND
((Main.[End Date]) Between [Close Date - Start] And [Close Date - End]))
GROUP BY Main.Category;
 
You could also comment out the first query stuff and see if the problem still occurs with the second query. Not much to say - just keep trying different things.
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I found the cause! I am enhancing an existing database and the initial developer uses an Attachment field, which I have never used.
When I removed that field the code works.
Of course, now I need to restore this field. Maybe it needs to be in a separate table.
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,998
Members
448,541
Latest member
iparraguirre89

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top