DAO Equivalent of OpenQuery

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to open a parameter query in Access in datasheet view. Here is the
code I'm using:

strQ = "My Query Name"
strPN = "My Parameter Name"
strPV = "My Parameter Value"

Set objQuery = CurrentDb.QueryDefs(strQ)
objQuery.Parameters(strPN).Value = strPV

DoCmd.OpenQuery strQ, acViewNormal, acReadOnly

However, the DoCmd.OpenQuery command still prompts me for the parameter
value. I can't see any methods of the QueryDef object that do the same thing
- is there something I'm missing?

TIA.
 
My advice would be to use Form based parameter queries. Have a form
named frmQueryParams. Then, you can have two text boxes, txtPN and
txtPV. your SQL of the query would be:

Select * from TABLENAME where fldPN = forms!frmQueryparams!txtPN and
fldPV = forms!frmQueryParams!txtpv


you could then just open the query: DoCmd.OpenQuery strQ,
acViewNormal, acReadOnly



Chris Nebinger
 
You should use a form.

Also, you should use a database object.

Set db = currentdb
set objQuery = db.QueryDefs(

If if what you are trying to do was a good idea (and it
is not), it still wouldn't work using CurrentDb instead
of a proper database object, because qdf's don't maintain
a parent reference.

(david)
 
Back
Top