View Full Version : query using a public variable


diversoln
10-21-2001, 04:52 PM
Is it possible to query using a public variable as the criteria ? I set up the public varible for the Part Number text field in my module using:

Public varGlobalPN As Variant

This variable can be reassigned on different several forms using a combo box. I'd like to be able to run the query and display a continuous form based on the value of this part number variable.

Also, how would I display a public variable on a form?

Pat Hartman
10-21-2001, 08:27 PM
In order to use a VBA variable in a query, you need to obtain it via a user defined function. Create a public function.

Public Function ReturnPN()
ReturnPN = varGlobalPN
End Function

Then in the query -
Select ...
From ...
Where SomePN = ReturnPN();

To display the variable directly on a form, create a control and use the following as its controlsource -
= varGlobalPN