Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User name

Status
Not open for further replies.

Nickaroo

MIS
Mar 24, 2003
21
US
If a user logs into the database with his/her Username and password. How can I get the username to be put into the data entry form?

Thanks
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top