Access 2007 - Calling a Parameter Query with VBA

smiley1978

Board Regular
Joined
Sep 13, 2005
Messages
133
I have the following code:

Set db = CurrentDb
Set dbQdef = db.QueryDefs("qSel_Pull_Data")

dbQdef.Parameters("Select Tier") = InputBox("Please select a tier.", "Select Tier")

Set rsResults = db.OpenRecordset("qSel_Pull_Data")

I get the following error message:

"Too Few parameters. Expected 1."


The query "qSel_Pull_Data" is a parameter query. There is a field in the query called [tbl_CommunicationLists]![Tier] that has the a parameter criteria [Select Tier]. In my VBA, I am using the InputBox to supply the tier (which is an integer).

I have tried to DIM the dbQdef as DAO.QueryDef but that did not change anything. Any assistance is appreciated.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
you went outside of the qdf.. by: set rsResults = db.OpenRecordset("qSel_Pull_Data")
the parameter is IN the qdf , so..

Set rsResults = dbQdef.OpenRecordset()
 
Upvote 0
Thank you. Now I get a data conversion error. Not sure if it is referring to the value that I enter or if the rsResults will not accept the open recordset. It works fine when I remove the parameters from the source query and just call the query in the VBA.
 
Upvote 0
The input box default value is text.
Change InputBox("Please select a tier.", "Select Tier") to InputBox("Please select a tier.", "Select Tier",,,,,,1)

InputBox(Prompt, Title, Default, Left, Top, HelpFile, HelpContextId, Type)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,849
Messages
6,162,425
Members
451,765
Latest member
craigvan888

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