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

Microsoft AccessSQL

Avatar of undefined
Last Comment
dschrishuhn

8/22/2022 - Mon
TextReport

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

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
TextReport

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
dschrishuhn

ASKER
It was a string.  Adding quotes did the trick.  Thanks for your help!

-Omar
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes