The following was the solution...
DoCmd.SetWarnings False
DoCmd.OpenQuery "QueryName"
DoCmd.SetWarnings True
I am interested in ClydeDoggie's example, to improve my VB...
dim rst as recordset
dim qdf as querydef
dim db as database
set db=currentdb
set qdf = db.querydefs("YourQueryName")
qdf.parameters(1)=Forms!frmMain!txtName
set rst=qdf.openrecordset
How do you specify which parameter gets which form!txtbox
e.g.
If my query has [Forms!frmMain!txtName] as a parameter and [Forms!frmMain!txtName2] as another parameter, then how would you differentiate between the two. Would you use...
qdf.parameters(1)=Forms!frmMain!txtName
qdf.parameters(2)=Forms!frmMain!txtName2
?
In addition, you stated...
"It's better code to use the Parameter Name instead of the index"
Do you mean I should use....
qdf.parameters(fieldname)=Forms!frmMain!txtName
qdf.parameters(fieldname2)=Forms!frmMain!txtName2
instead of the column number?
Also, how would use the above code assuming you have the following formula in place.....
myfieldformula: field1*field2/Forms!frmMain!txtName
Will the above work if I use
qdf.parameters(myfieldformula)=field1*field2/Forms!frmMain!txtName
And if so how do I index which column it will be.
I now this is a lot, so thank you!
P.S. I'm using Access 2002 from Office XP.
