Public Variable

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
 
L

Larry Linson

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
 

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