I would recommend instead, if possible, rather than creating a table with usernames and passwords, to use the network logon username. This is a common mistake is access database authors creating an overly complex system where users have to create their own username and password.... Now sometimes that's necessary depending on your user set up (lack of a network and separate PCs).
But if your users are setup on a typical company network and they each log on using their own unique logon, then creating either usernames OR passwords is unnecessary and less secure.
Just use a brief code to get the current network username, which is 100% secure (to the degree you trust your IT department, but my point is, security becomes their responsibility), and no passwords at all are necessary.
After you do that, the answer to this question then becomes:
1) set up a table that simply saves the information of which logon id has access to the database, and/or has access to some other things in your DB.
2) call the
GetUserID() function each time it's needed. (it runs instantaneously, so there is no need to save anything in a public variable, which may lose its value when untrapped errors occur).
Last but not least, if you insist on setting it up the way you are, I'd recommend using TempVars instead of a global variable....and even better than that, I'd recommend storing the value in an unbound / hidden textbox on a form that remains open as long as the database is open; either of these is more reliable and less prone to fail than a public variable.