Help with getting user name (1 Viewer)

SmudgerGTS

New member
Local time
Today, 13:07
Joined
Mar 16, 2020
Messages
23
Hi everyone,

Need a bit of help here due to my lack of knowledge.

Have a table that has fields DelUser & DelUserTime along with other fields. My intension is to use the fields as a "Time Stamp" of when the particular record was created or modified.

I wish the system to auto populate these fields. DelUser will be the login name of the user on their PC. DelUserTime will be taken from the PC system clock.

I have zero VBA knowlege.

Thanks
 

Minty

AWF VIP
Local time
Today, 13:07
Joined
Jul 26, 2013
Messages
10,371
You can get the current windows user name from the following;
Code:
Dim strPcUser as String

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

The current date and time is simply Now()
 

deletedT

Guest
Local time
Today, 13:07
Joined
Feb 2, 2019
Messages
1,218
You can use The following for user name.
Environ("UserName")

Current date and time would be Now()

Edit: Seem that @Minty was faster....
 

SmudgerGTS

New member
Local time
Today, 13:07
Joined
Mar 16, 2020
Messages
23
Thanks guys for quick responses,

Please forgive my ignorance but where do i put the code ?
 

deletedT

Guest
Local time
Today, 13:07
Joined
Feb 2, 2019
Messages
1,218
It depends but maybe the best place is Default Value

1- Open your form in Design mode
2- Select the textbox that you want to set the time stamp
3- Press F4 to show the Property Sheet
4- Select Data Tab
5- Find Default Value and type =Now()

Go through steps 1 to 4 For UserName textbox.
Type =GetDefault_UserName() for Default Value.
Then Open Visual Basic Editor by pressing Alt+F11
in one of your modules paste the following:
SQL:
Public Function GetDefault_UserName()
    GetDefault_UserName = CreateObject("wscript.network").UserName
End Function


OR

SQL:
Public Function GetDefault_UserName()
    GetDefault_UserName = Environ("UserName") 
End Function

Now when you open your form and go to a new record you have your default values.
 

SmudgerGTS

New member
Local time
Today, 13:07
Joined
Mar 16, 2020
Messages
23
Thanks Tera, works a treat - once I'd figured out what a Module was and how to add one 🤔
 

Users who are viewing this thread

Top Bottom