Get User log in - API not backwards or forward compatible (1 Viewer)

basshead22

Registered User.
Local time
Today, 00:11
Joined
Dec 17, 2013
Messages
52
Hello All,

I used the code in the link below to get the login id returned on a form but I am having trouble now that I rolled out the database the code gives an error if the user has older than 2010 and even on a new machine that has access 2013 what is the best code to use? to return the log in id to a form?? without worrying about what version of access they have it wont be older than 2003.

http://access.mvps.org/access/api/api0008.htm



Much appreciated.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 17:11
Joined
Jan 20, 2009
Messages
12,853
Some will pipe up with code to return the Username environment variable.
Avoid it becaus eit is easy to break.

This will return the actual username.

CreateObject("wscript.network").username
 

basshead22

Registered User.
Local time
Today, 00:11
Joined
Dec 17, 2013
Messages
52
Thank you for your reply Galaxiom..

where do I put this code , sorry im fairly new to programming is it VB a Macro / module?
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 17:11
Joined
Jan 20, 2009
Messages
12,853
Put this function in a Standard Module and you can use it anywhere in the project.

Code:
Public Function LoginName()
    LoginName = CreateObject("wscript.network").UserName
End Function
 

Users who are viewing this thread

Top Bottom