Donate SIGN UP

Access 2003 VBA Get User ID

Avatar Image
TheUnderTow | 14:58 Thu 07th Sep 2006 | Technology
1 Answers
GetUserID used to work in previous versions of Access to populate a combo box with the user but this seems to have been removed from 2003 - does anyone know any code to replicate this? I'm running on Window XP if that makes a difference...
Gravatar

Answers

Only 1 answerrss feed

Best Answer

No best answer has yet been selected by TheUnderTow. Once a best answer has been selected, it will be shown here.

For more on marking an answer as the "Best Answer", please visit our FAQ.
Put this bit of code in the declarations section of a module

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

then create this function

Public Function GetUserName() As String
On Error GoTo Err_Handler

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
GetUserName = Left(strUserName, lngLen - 1)
Else
GetUserName = vbNullString
End If

Exit_Handler:
Exit Function

Err_Handler:
Resume Exit_Handler
End Function

Only 1 answerrss feed

Do you know the answer?

Access 2003 VBA Get User ID

Answer Question >>

Related Questions

Sorry, we can't find any related questions. Try using the search bar at the top of the page to search for some keywords, or choose a topic and submit your own question.