Access vba code to get user name in comp. environment and update in a table

Rakesh935

Registered User.
Local time
Today, 20:04
Joined
Oct 14, 2012
Messages
71
Hello All,

Requesting to please help me for the below mentioned requirement...

I have a access file having a form and a table all i need is a code or some guidance in buiding the code in order to "recognise the user name in the computer environment and the same must get updated automatically in the table (in a purticular column) of the access file in order to figure out who all have accessed/used the file."

Thank you,
Rakesh
 
Create a table that will have nothing more than three fields,
tblLogUserAccess
logID - Autonumber (PK)
logUser - Text
logDate - Date/Time (General date)

Create a Form(hidden) call it loggerFrm; does not have any controls, have it open by using the AutoExec Macro.. Then in the OnLoad event of the loggerFrm have this code..
Code:
Private Sub Form_Load()
    Dim myQry As String
    Dim sUserName As String
   [COLOR=Green] ' Get Current User Name[/COLOR]
    sUserName = Environ$("username")
    [COLOR=Green]' If you want Computer Name use Environ$("computername")[/COLOR]
    myQry = "INSERT INTO tblLogUserAccess (logUser, logDate) VALUES ('" & sUserName & "',#" & Now() & "#)"
    CurrentDB.Execute myQry
End Sub
This will add an entry into the table everytime automatically.. Since the Form is hidden no one will know it is doing it in the background..

Post back if you find it hard to follow..
 
Hi,

Thanks for the help....

Mean while it would be really great if could help me a liitle more in doing an "AutoExec Macro" since i very much new into the field of macros of ms access...

Thanks,
Rakesh
 
Environment variables are a very unreliable way to verify the user because they can easliy be changed from the default by the user.

Better to get the actual information:

LoginName = CreateObject("wscript.network").UserName

MachineName = CreateObject("wscript.network").ComputerName
 
Mean while it would be really great if could help me a liitle more in doing an "AutoExec Macro" since i very much new into the field of macros of ms access..

Create a macro, with OpenForm action and name it AutoExec. This macro shall fire automatically whenever dB is opened.
 
..... have it open by using the AutoExec Macro..
The word AutoExec Macro is a hyperlink where it describes how to create one..
Environment variables are a very unreliable way to verify the user because they can easliy be changed from the default by the user.
Never used these before, actually did not know that Environ does not always give the right value.. Thanks for the heads up Galaxiom.. Will use that, this one does not need any Reference does it?
 
Hi,

Thanks everybody for the help. Lastly, requesting a little more help for the below mentioned requirement...

How can i capture the computer name into an existing table which has a multiple form too...

thanks
Rakesh
 

Users who are viewing this thread

Back
Top Bottom