"Top Values=X" where "X" is passed from form to the Query Property

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a query that I am using to randomly select employees from our employee
database for drug screening, and would like to allow the manager to make the
selection from a button on a form. I know how to create the form, etc, the
problem I am having is that I want the manager to be able to provide the
number of employees to randomly select at runtime (without having to modify
the query each time.) So....how can I pass a value that the manager inputs on
a form at runtime to the query property "Top Values" ? The field in query
properties will not allow me to type in a formula, only an integer value.

Thanks !
 
You will need code to modify the SQL String of the Query as in "Top X", "X"
cannot be a Parameter (AFAIK).

Create the QueryDef object (think of it as the Query in code) and modify its
SQL String to the suitable X so that in the resultant SQL, X becomes
explicit.

Close the QueryDef (which will save the Query with the modified SQL) and
then run the Query by code.
 
Back
Top