Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Q: User names and their use/handling etc...How? 2

Status
Not open for further replies.

mikeg8

Technical User
Sep 11, 2003
32
GB
I'm writing a small application and wish to record the user's name in each record (so I can find out who entered all the wrong data!)

Has anyone got any hints, tricks or tips about doing this such as entering user name (can this be retrieved from Windows XP?), best way to store user name (name-text or number-id) etc

Mike
 
I have a brief list of usernames you can grab from either Access' built-in security, or the Windows logon, or the computer name... faq181-3779

Basically, there will be some sort of function you call to grab the username. You can put this in the query in place of any other expression. To put this in a form/data entry, you'd have to work with the form events or maybe just put something like "=CurrentUser()" for the DefaultValue property of your username control.

 
Put the following in a Public Module:


Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function UserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
UserName = Left$(strUserName, lngLen - 1)
Else
UserName = vbNullString
End If

End Function


IT Professional
 
Thank you Foolio12 and Kocheace, I'll try all suggestions and see how I get on.

Mike
 
If your system is on a netwrok of users, you can get the usernames by simply doing this

Dim sUserName as String

sUserName = Envrion("User")

This gives you the name of the person logging into the network at any time.
 
Mikeg8,

Once you've copied that code to a module, open the immediate window and type ?username() then "Press Enter".

The user whose currently logged on to windows will appear under your ?------- statement

Say 'ello..... to my little friend!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top