I tried the syntax you sent me, but it gave me an error
message where Set prm is.The syntax I used is the
following, please let me know what I'm missing.
Dim qdf As DAO.QueryDef, prm As DAO.Parameter
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Set qdf = db.QueryDefs("qry_UCRsFinal")
Set prm = qdf.Parameters!ParameterName
Set prm = [Forms]![frm_SupervisorsLogin]!
[txtSupervisorLogin]
Set rst = qdf.OpenRecordset
Set rst = Nothing
Set prm = Nothing
Set qdf = Nothing
Set db = Nothing
DoCmd.OpenQuery "qry_UCRsFinal"
-----Original Message-----
If the parameter is already defined in the query, you can specify the
parameter name in code then open the query as a recordset.
Example:
Dim qdf As DAO.QueryDef, prm As DAO.Parameter
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Set qdf = db.QueryDefs("qryMyQuery")
Set prm = qdf.Parameters!ParameterName
prm = Me.txtMyTextbox
Set rst = qdf.OpenRecordset
Set rst = Nothing
Set prm = Nothing
Set qdf = Nothing
Set db = Nothing
To specify a parameter value for a stored query that you will be opening in
spreadsheet view, it would probably be easiest to point the parameter to a
control (hidden if you wish) on the form and set the value of that control
in your code before you open the query.
Example:
Criteria in the query:
Forms!frmMyForm!txtMyTextbox
Then in the button's click event
Me.txtMyTextbox = 5 'or whatever you want
DoCmd.OpenQuery "qryMyQuery"
--
Wayne Morgan
Microsoft Access MVP
.