Using a global variable as criteria in a combo box

D

DCPan

Hi,

I have a global variable declared to store the employee id of the user that
is logged into the Access front-end.

I want to use that global variable as a limiter in the combobox so that the
combobox only pulls the employees that have supervisor ID that matches the
global variable.

However, I can't seem to get the syntax correct for the global variable to
be accessed. Instead of pulling the global variable, it comes up as a prompt
when the query is triggered.

Is there an easier way to do this than assigning that global variable to a
hidden textbox on the form to drive the query?

Thanks!
 
G

George Nicholson

If glngEmpID is your global variable, add the following to a general (i.e.,
not a form) code module:

Public Function GetEmpID() as Long
GetEmpID = glngEmpID
End Function

Then, in your query, use "GetEmpID()" for the criteria (without quotes but
*with* the parenthesis)

HTH,
 
M

Marshall Barton

DCPan said:
I have a global variable declared to store the employee id of the user that
is logged into the Access front-end.

I want to use that global variable as a limiter in the combobox so that the
combobox only pulls the employees that have supervisor ID that matches the
global variable.

However, I can't seem to get the syntax correct for the global variable to
be accessed. Instead of pulling the global variable, it comes up as a prompt
when the query is triggered.

Is there an easier way to do this than assigning that global variable to a
hidden textbox on the form to drive the query?


VBA variables, global or otherwise are only known to VBA
code. You can create a Public function in a standard module
to return the value of the variable. E.g.

Public MyVar As Long
Public Function GetMyVar()
GetMyVar = MyVar
End Function

I think the text box on an always open form is a better
approach, because the value will not be reset when an
unhandled error occurs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top