How do I capture the windows log on information of a user using a database?

solrac_otos

Registered User.
Local time
Yesterday, 19:44
Joined
Apr 4, 2014
Messages
19
I was hoping someone could help me with this.

I have several data entry forms in my DB. What I would like to do is capture the windows user name of the people adding records and changing records. How do I go about doing that? I was think of an on change event to a given field that would then pull the username and insert it in another field/object.

Lets say the an on change of me.cmbModel update txtUserName.

Any help you can provide would be greatly appreciated.

Kind regards.

-C.
 
Use the BeforeUpdate event of the Form. That is the last form event that will be triggered before committing a record to the table.
 
Ok...but what is the code for pulling the user name information? Thats the part I am really stuck on :-/

Thanks for the reply.
 
Something like,
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    Me.yourLastUpdateField = Environ("username")
End Sub
For better reliability, some people use fOSUserName function.
 
Thanks all. I worked this all out thanks to the input.

-C.
 
Something like,
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    Me.yourLastUpdateField = Environ("username")
End Sub
For better reliability, some people use fOSUserName function.



Just so you understand what pr2-eugin was telling you to do, Using the Environ() function will return any environment variable (system or user created) by passing its name as the parameter. "Username" is a windows system default environment variable but can be changed by system administrators.

To view your system variables and their names, the easy way on Windows 7, click start, in the search box type "Environment Variables" then click "Edit Environment Variables for your account" or for system variables that can be accessed by admin click "Edit the system environment variables".


He is correct in stating that using the API (Application Program Interface) call to return the current logged in user is much more robust and less likely to cause problems should something unknowingly is changed.
 

Users who are viewing this thread

Back
Top Bottom