In kind of a hurry to leave, but I'll give it a shot. You can dimension a global variable in a module's declarations section.
Then when the user logs on, entering their username, you can set the global variable to that user's username.
Since the variable is global, you can use it when the data entry form is opened. Like in the OnOpen event:
txtUser = gstrMyGlobalVariableName
Here are some examples of globals I created in one application some time ago;
Global vUserId As Long
Global strSQL As String
Global vMsgBox As Variant
Global dbs As Database
Global qdf As QueryDef
Global rst1 As Recordset
Global Main As Form
There is an even easier way, that is, if the user accounts in your appliation are the same as the users' NT IDs on the network. Or... at least the same as the username they log onto their PC with.
Anywhere you want to use this method, and at any time, its simply:
Environ("UserName"
For example, if you want to have their username show up in the username field on the logon form, simply set the default value of that field to:
=Environ("UserName"
If you want that name to appear by default in the data entry form, set the default value of that text box to:
=Environ("UserName"
When I first found this out I was amazed at the simplicity of it. I hope you can use it to. Or the global variable thing works, if you can't use the Environ variable.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.