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

Windows login info 3

Status
Not open for further replies.

raminriahi

Programmer
Sep 9, 2002
31
0
0
US
Is there any way (builtin function) to grab the windows login user id within the access?

Thanks in advance,

Ramin Riahi
 
i found this code on here a while ago and use it all the time.
add this code to a module:

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

Function fWin2KUserName() As String
Dim lngLength As Long, lngx As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLength = 255
lngx = apiGetUserName(strUserName, lngLength)
If lngx <> 0 Then
fWin2KUserName = Left$(strUserName, lngLength - 1)
Else
fWin2KUserName = "unknown"
End If
End Function

then to use it do something like this:
textbox = fWin2KUserName()

or you could use:
textbox = Environ("username")
 
Excellent drctx!

Thanks so much for your help !

Ramin
 
For WinNT, Win2k, WinXP and Win2003 platform:
Environ("UserName")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top