QueryDef with parameters - item not found (1 Viewer)

dj59

Registered User.
Local time
Today, 05:16
Joined
Jul 27, 2012
Messages
70
I am getting an error.
Item not found in this collection - runtime error 3265.
I've searched online for the answer and I found that it is due to something incorrect in the spelling, etc.
However, I have checked and rechecked.
The query name is qry_55
The field is c.cnty_cd - However this query is run from an sql statement that Has the following from statement:
Code:
....FROM sw_cty_pd AS c
My qryDef code is as follows:
Code:
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim rst As DAO.Recordset
    Set qdf = CurrentDb.QueryDefs("qry_55")
    qdf.Parameters("c.cnty_cd").Value = "01"
    Set rst = qdf.OpenRecordset

Does this need to be written differently because I named the table in the query 'c'?
Thanks for any help on this.
 

MarkK

bit cruncher
Local time
Today, 03:16
Joined
Mar 17, 2004
Messages
8,179
You can check the parameter names with something like . . .
Code:
dim var
for each var in currentdb.querydefs("qry_55").parameters
   debug.print var.name
next
 

dj59

Registered User.
Local time
Today, 05:16
Joined
Jul 27, 2012
Messages
70
Thank you that showed where my problem was.
 

jdraw

Super Moderator
Staff member
Local time
Today, 06:16
Joined
Jan 23, 2006
Messages
15,379
It may help others if you tell them what the issue was.

Sharing what you learn is helpful to all.
 

dj59

Registered User.
Local time
Today, 05:16
Joined
Jul 27, 2012
Messages
70
this code:
Code:
dim var
for each var in currentdb.querydefs("qry_55").parameters
   debug.print var.name
next

showed me the var name. It looked the same as what I had in the code.
I decided to copy the name from the sql and insert it to be certain it was exactly the same. That fixed it. Then I notied that there was no space in the sql where there was a space in my parameter name.
 

Users who are viewing this thread

Top Bottom