Add Window Username to Table

sefa333

Registered User.
Local time
Today, 03:11
Joined
Nov 17, 2011
Messages
19
Thanks in advance for your help. I am still new to Access code.
I was wanting to know if there is a way to Add the Username to a table as a default value when a new record is added. I know you can add =Date() to get the date. Is there a simple way to get the ID of the person logged into Window? Thanks again.
 
Copy this function into a Standard Module.
Code:
Public Function LoginName()
    LoginName = CreateObject("wscript.network").UserName
End Function

Use the function as the default value of a textbox on the form bound to the field in the table where you want to write the username. The textbox can be hidden.
 
Thank you very Much. It works great!!
 
what would be the default value for my text box?

Whatever I name the module? I tried giving the module "username" but when I do that in the default value it thinks it a table or field and puts it in brackets.
 
The module can be pretty much any name except the name of a sub/function or the project name.

The module name is not used in the reference. Just the function name.
 
I have been using =Environ("username") for this.
 
I have been using =Environ("username") for this.

So do a lot of other developers. However it isn't a very good choice because environment variables can be tampered with.

Better to use the actual username from the system.
 

Users who are viewing this thread

Back
Top Bottom