Link to home
Create AccountLog in
Avatar of dschrishuhn
dschrishuhn

asked on

SQL Parameters run-time 3061

Hello,

In VBA, I'm trying to open a DAO recordset.  I got Run-time error 3061 "Too Few Parameters.  Expected 1".  So I added a parameters clause

"PARAMETERS [ID] string; " _

To the SQL string.  Now I get  "...Expected 2" --??

qryOpenAgedReq  is a Union:

SELECT * FROM tblAgedInvoicesIDFix UNION ALL SELECT * FROM tblRequestedInvoicesIDFix;

Both table have identical fields.

Thanks in advance!

-Omar



Dim db As DAO.DATABASE
Dim SQL As String
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
 
Set db = CurrentDb()
 
SQL = "PARAMETERS [ID] string; " _
    & "SELECT PO, AP_Vendor, Vendor_Name, User_ID_Assigned " _
    & "FROM qryOpenAgedReq " _
    & "Where qryOpenAgedReq.ID = " & ID & ";"
Set qdf = db.CreateQueryDef("", SQL)
Set rst = qdf.OpenRecordset

Open in new window

Avatar of TextReport
TextReport
Flag of United Kingdom of Great Britain and Northern Ireland image

Remove the PARAMETER part of the SQL, you are not using it.
Cheers, Andrew
SQL = "SELECT PO, AP_Vendor, Vendor_Name, User_ID_Assigned " _
    & "FROM qryOpenAgedReq " _
    & "Where qryOpenAgedReq.ID = " & ID & ";"
Set qdf = db.CreateQueryDef("", SQL)
Set rst = qdf.OpenRecordset

Open in new window

Avatar of dschrishuhn
dschrishuhn

ASKER

That was how my code looked originally.  When I run it like that I get "Run-time error ' 3061': Too few parameters.  Expected 1."

When I added the PARAMETER clause, I got the same error except "Expected 2"
ASKER CERTIFIED SOLUTION
Avatar of TextReport
TextReport
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
It was a string.  Adding quotes did the trick.  Thanks for your help!

-Omar