If I set up Access security measures so that each user will be asked to log on with a password, is there a way to capture their user id into a Global Variable? If so, how?
Not sure if you mean Access Logon User ID or Network ID. For Access it's:
CurrentUser()
Otherwise it's:
Delclare this API in any module:
Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize _
As Long) As Long
Then use this function:
Public Function GetUser() As String
Dim l As Long, sUser As String
On Error Resume Next
sUser = Space$(255) 'Init string
l = GetUserName(sUser, 255) 'call API
'strip null terminator
If l <> 0 Then
sUser = Left(sUser, InStr(sUser, Chr(0)) - 1) 'null terminated string
If Len(sUser) > 50 Then
sUser = Left$(sUser, 50)
End If
GetUser = sUser
Else
GetUser = "<Not Found>" 'raise an error msg here if you like
End If
End Function
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.