QueryDefs? Parameters?

M

M

I have this code:

Dim db As Database
Dim qdf As QueryDef
Dim prm As Parameter
Dim rs As Recordset
Set db = CurrentDb()
Set qdf = db.QueryDefs("nameofquery")
For Each prm In qdf.Parameters
Set prm.Value = Eval(prm.Name)
Next prm
Set rs = qdf.OpenRecordset(dbOpenDynaset)

and the query I want to run has a parameter set:

Forms!frmMain!txtBeginningDate

I get an 'Object Required' error when I run the code. What
have I left out?

Thanks
 
B

Brendan Reynolds

I haven't tested this, but looking at the code I think the problem is the
line "Set prm.Value = Eval(prm.Name)". "Set" is used to assign a reference
to an object to an object variable, but what you're doing here is assigning
a value to a property of the object variable. In other words, I think you
just need to take "Set" out of that line.
 
J

John Flanagan

Is frmMain open when you run the query?
(don't be insulted, I don't know who I'm addressing)

John
 
M

M

I did remember this time to keep the form open. I realized
I hadn't mentioned that when I originally posted. But I
have been known to forget those types of things from time
to time.

Thanks

M
 
M

M

That did it! Thanks for your help.

M

-----Original Message-----
I haven't tested this, but looking at the code I think the problem is the
line "Set prm.Value = Eval(prm.Name)". "Set" is used to assign a reference
to an object to an object variable, but what you're doing here is assigning
a value to a property of the object variable. In other words, I think you
just need to take "Set" out of that line.

--
Brendan Reynolds (MVP)




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top