Public Variable

  • Thread starter Thread starter Mei Qin
  • Start date Start date
M

Mei Qin

Hello,

I declared a public variable strUserID in a module. In my
query, I would like to use this variable as the selecte
criteria. Like select * from table where userID =
strUserID. In the module where the code runs to generate
report based on the above query, I set the value of the
userID to the actual user. But I got error asking me to
input strUserID when I generating reports. How can I
reference this variable in the query?

Thanks for the help!

Mei
 
You cannot refer to a variable in a Query. You can refer to a user-defined
function, so you can create a function whose purpose is to return the value
you want.

Public Function WhoAmI () as String
WhoAmI = CurrentUser()
End Function

and, you will not need a public (global) variable.

Larry Linson
Microsoft Access MVP
 
Back
Top