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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Access Security Features - Is there a way to capture the ID?

Status
Not open for further replies.

ChemistZ

Programmer
Oct 30, 2001
70
US
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?
 
The following thread may help. I did a search on this site and found it...

thread181-3719 Terry M. Hoey
 
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 = &quot;<Not Found>&quot; 'raise an error msg here if you like
End If
End Function

Works well,
--Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top