too few parameters error msg

amypaulsen

Board Regular
Joined
Mar 1, 2004
Messages
114
This is the code I'm using in VB-Excel to pull info out of access:

Set objDB = objAccess.currentdb()
With objDB

strSQL = "select " & QueryName & ".UNIT, " & QueryName & ".CATEGORY, " & QueryName & "." & WeekNum & " from " & QueryName & " where category = '" & CatName & "';"

Debug.Print strSQL

Set rst = objDB.openrecordset(strSQL)

When I run this, I keep erroring out on the last line "Set rst = objDB.openrecordset(strSQL)" stating: too few parameters, expected 1

When I hover over the SQL statement or look in the locals window, it is clearly recognizing what to pull.

What the HECK am I doing wrong????

Please help!
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Amy

If you can, try copying the strSQL into a new query in the Access DB where you are trying to pull the info from.

There might be something in the Access queries that you are trying to query that is not in you're strSQL, it might be a Group By or Sum.

Look at the SQL of the original queries and see if there is anything that is not in you're strSQL.
 
Upvote 0
Amy, when you run a query in code, any parameters have to be specifically evaluated. Here's what I do in Access:

Code:
Dim dbs as DAO.DataBase
Dim rst as DAO.Recordset
Dim qdf as DAO.QueryDef
Dim prm as DAO.Parameter

Set dbs=CurrentDB()
Set qdf=dbs.QueryDefs("YourQueryName")
For each prm in qdf.Parameters
   prm=EVAL(prm.value)
[or it could be, prm.Value=EVAL(prm) -- don't have the code with me at the moment]
Next prm

...open the recordset here
Hope this helps

Denis
 
Upvote 0

Forum statistics

Threads
1,221,808
Messages
6,162,097
Members
451,742
Latest member
JuanMark10

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