How do I retrieve the Access security username

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to use the username to auto populate the employee field when clearing
a ticket. Can it be pulled from the information that they logged in with
(not windows password).
 
The VBA CurrentUser() function returns the name of the current user as
defined in the workgroup information file.

In an unsecured database, you are not requested to log-on, and the
username will always be "Admin". In a secured database, you /are/
requested to log-on, and the username will be whatever username you
logged-on with.

HTH,
TC
 
I need to retrieve the employee ID (username) that they use to login into our
Access database. (I set up rights using the security wizard and it works
pretty well.)

What I am hoping for is a simple command that can be inserted into a query
or macro. If I must use VBA, I will take the information my tech at the
office.

Thanks!
 
Mark said:
I need to retrieve the employee ID (username) that they use to login
into our Access database. (I set up rights using the security wizard
and it works pretty well.)

What I am hoping for is a simple command that can be inserted into a
query or macro. If I must use VBA, I will take the information my
tech at the office.

That is what TC gave you. In the same way that you can use Date() or Now() in a
query you can use CurrentUser() and it will give you what you want.
 
Mark said:
I want to use the username to auto populate the employee field when
clearing a ticket. Can it be pulled from the information that they
logged in with (not windows password).

Perhaps you are looking for logged in username of the computer or
network vs. database username. You might want to use something like this
in a module:

'----------------------------------------------------------------------------------
'GetUserName
'
'Purpose:
' This service defines the Library routine to fetch the Network UserName.
'
'Parameters:
'
'Rev Num Date Author Description of Change
'------- -------- ------
-----------------------------------------------------
' 001 03/01/99 ash Code Courtesy of Dev Ashish
'----------------------------------------------------------------------------------
Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As
Long

'----------------------------------------------------------------------------------
'ReturnUserName
'
'Purpose:
' This service returns the Network UserName.
'
'Parameters:
' None.
'
'Rev Num Date Author Description of Change
'------- -------- ------
-----------------------------------------------------
' 002 05/25/99 ash Trim Numeric chars from end of UserName
' 001 03/01/99 ash Code Courtesy of Michael Kaplan
'----------------------------------------------------------------------------------
Public Function ReturnUserName() As String
On Error Resume Next

Dim sBuffer As String
Dim lSize As Long

sBuffer = Space$(255)
lSize = Len(sBuffer)
'sbuffer includes an Ascii.Null. lSize is one larger than the real
length.

Call GetUserName(sBuffer, lSize)
If lSize > 0 Then
lSize = lSize - 1
If IsNumeric(Mid$(sBuffer, lSize, lSize)) Then
lSize = lSize - 1
End If

ReturnUserName = Left$(sBuffer, lSize)
Else
ReturnUserName = vbNullString
End If

End Function
 
Back
Top