Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Paramater Query in VBA

Status
Not open for further replies.

carefully

Programmer
Mar 14, 2000
8
CA
Using a VBA module I am getting a runtime error "3061 Too few parameters expected 1"
when the last line of code below is executed

The critical elements are

Dim rst1 as DAO.recordset
Dim rst2 as DAO.recordset
Dim strSQL as String
Dim numID as Long

Set dbs = CurrentDb
Set rst1 = dbs.OpenRecordset("qryA", dbOpenDynaset)

...
strSQL = "SELECT tblA.Field1, tblB.Field2
FROM tblA INNER JOIN tblB ON tblA.Field3 = tblB.Field3
WHERE tblA.Field1 = numID ;"

Set rst2 = dbs.OpenRecordset(strSQL)

...

numID is being generated correctly earlier from rst1 and if I substitute a
number into the SQL statement directly the program functions fine.
I have managed similar coding with dates and string as as parameters but am stumped
here where the parameter is a number
 
You are defining numID as a variable in the module. I gather somewhere in the deleted code, you are loading a value into it, but then when you load strSQL you are just filling it with a string (not appending the variable to the string). You need something like:
Code:
strSQL = "SELECT tblA.Field1, tblB.Field2
    FROM tblA INNER JOIN tblB ON tblA.Field3 = tblB.Field3
    WHERE tblA.Field1 = " & numID & ";"

I could be wrong on the exact format, but I bet I am really close...

Terry M. Hoey
th3856@txmail.sbc.com

Ever notice that by the time that you realize that you ran a truncate script on the wrong instance, it is too late to stop it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top