getting user names from windows

G

gvaughn

I trying to pull the user names from windows environ to use in an access
interface to log-in, log-out. I have some code:

Function UserNameWindows() As String
UserNameWindows = VBA.Environ("USERNAME") & "@" & VBA.Environ("USERDOMAIN")
End Function

but I am having trouble getting the field to call the function. How can I
get a username field in a tabel to call the function to get the windows user
name? ANy help would get appreciated
 
T

Tom Wickerath

Instead of using environment variables, which can be compromised by a
knowledgeable user, I suggest using an API call. If you only needed the
user's NTLoginID, I'd say go for this method:

Get Login name
http://www.mvps.org/access/api/api0008.htm

Since you need both user name and domain, use this method instead. Disregard
the "ACC2000" in the title of this article:

ACC2000: How to Retrieve Workgroup Information Under Win32
http://support.microsoft.com/?ID=210088

but I am having trouble getting the field to call the function. How can I
get a username field in a table to call the function to get the windows user
name?

You cannot do this using a JET (.mdb) or the newer Private JET (.accdb) of
Access 2007, since these engines do not include any programmable events at
the table level. However, you can run the GetWorkstation function shown in KB
210088 by calling it in your startup code. You can write the values to a
login table, if that's what you need or want to do.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top