golfman119
03-26-2002, 04:32 PM
Is there a way to pass a parameter to a parameter query via code and have the query excute, and view the recordset in a form or a report,with out that dialog box asking for the parameter ie the code will take care of entering the parameter in the dialog box behind the seen and the result will show on a form or report
KKilfoil
03-27-2002, 04:56 AM
Sample fragment to pass a variable as a parameter to a query in VBA:
Dim dbs As Database
Dim rst As Recordset
Dim qrydef As QueryDef
Dim YourVariable as long '{for example}
Set dbs = CurrentDb
YourVariable = 7 '{for instance}
Set qrydef = dbs.QueryDefs!qryYourQuery
qrydef![TheQueryParameter] = YourVariable
Set rst = qrydef.OpenRecordset 'opens or runs your query
.
.
whatever you want to do with the query
.
.
rst.Close
Set rst = Nothing
dbs.Close
Set rst = Nothing
++++++++++++++++++++++++++++++++++++
Sample to pass a parameter to a query in VBA if the query normally needs a parameter from a form control:
'note that form must be open for this to work!
Dim dbs As Database
Dim rst As Recordset
Dim qrydef As QueryDef
Set dbs = CurrentDb
Set qrydef = dbs.QueryDefs!qryYourQuery
qrydef![forms!frmYourForm!txtYourControl] = [Forms]![frmYourForm]![txtYourControl]
Set rst = qrydef.OpenRecordset 'opens or runs your query
.
.
whatever you want to do with the query
.
.
rst.Close
Set rst = Nothing
dbs.Close
Set rst = Nothing
[This message has been edited by KKilfoil (edited 03-27-2002).]
golfman119
03-27-2002, 02:50 PM
Thanks very much for the help . I followed your your sample code , and it works fantastic thanks again
David