Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parameter Queries 1

Status
Not open for further replies.

gavinjb

Programmer
Apr 24, 2003
106
GB
Does anyone know how to change a Parameter in either ADO/DAO.

I have a query Called qryDailyReport which has a Parameter Called StartDate, which I need to be able to Change in Code, after searching Help I can find plenty of information on how to Create Parameter Queires from scratch but nothing on how to set the vlaues in one.

Gavin,
 
I use this technique in my queries. For example, I have a query which lists information for one employee, taken from an Employees table. I pass this query a parameter taken from a 'chooser' form - but you could set the value in VBA code any way you like.

First, create a public variable in the (declarations) section of a module:
Code:
Public strChooserID As String

Now, create a small public function in the module:
Code:
Public Function GetChooserID()
    GetChooserID = strChooserID
End Function
In the query design view, set the Criteria cell for the field to be filtered equal to the function name. In my example, I set the EmployeeID field criteria to:
Code:
GetChooserID()
You can now set the value of the public variable when the user clicks a button, chooses an option from a drop-down list etc. The value of this variable will be passed via the function to the query.

I hope that this helps.


Bob Stubbs
 
Thanks, that worked perfectly for my requirements
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top