Variable Accros Queries

  • Thread starter Thread starter Paul W Smith
  • Start date Start date
P

Paul W Smith

If I wish to use a variable across mutliple queries, is this possible, and
if so where would I declare and set the variable?
 
You can't use variables in queries.

Are you thinking in terms of selection criteria (i.e. parameters), and you
don't want to have to input the same parameters multiple times, or do you
want the value stored in a variable to be returned by the query?

For the former, the easiest approach is to create an unbound form with
controls on it, one for each parameter. Have the query refer to the controls
(the syntax is Forms![NameOfForm]![NameOfControl]), rather than using named
parameters (such as [Start Date]). Make sure the form is open before you run
the queries: Access will not open the form for you.

For the latter, create public functions that return the values of the
variable, and use the function in the query. For example, if you've got a
public variable X, you can create a function:

Public Function XValue() As Long

XValue = X

End Function

and then use XValue() in your query.
 
Back
Top