parametr qry purely in code

  • Thread starter Thread starter max
  • Start date Start date
M

max

I would like to create a parameter query purely in code.
(as opposed to refering to an already created param qry
object like below

"Set QDef = db.QueryDefs("MyQuery")

The parameters should be passed to the query through a
function in a txtbox of a report.
How do I go about this?
 
I would like to create a parameter query purely in code.
(as opposed to refering to an already created param qry
object like below

"Set QDef = db.QueryDefs("MyQuery")

The parameters should be passed to the query through a
function in a txtbox of a report.
How do I go about this?

A Query object has a Parameters collection: you can set each member of
that collection to any appropriate value. e.g.

QDef.Parameters(0) = strThis
QDef.Parameters(1) = Format(dtDatevalue, "\#MM\/DD\/YYYY\#")

If the parameters refer to controls on an open form, e.g.

Parameter [Forms]!{MyForm]![txtA];
SELECT ...
.... WHERE fieldname = [Forms]![MyForm]![txtA]...

you can use a loop:

Dim prm As Parameter
Set QDev = db.QueryDefs("MyQuery")
For Each prm In QDev.Parameters
prm.Value = Eval(prm.Name)
Next prm
 
Back
Top