UserNameWindows() & UserNameOffice()

G

George

why do UserNameWindows() & UserNameOffice() work in Excel but not Access, how
can I get this info?
 
K

Ken Sheridan

Probably the most reliable is to call the Windows API by adding the
following module to the database:

''''module starts''''
Option Compare Database
Option Explicit

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


Public Function GetUser() As String

Dim strBuffer As String
Dim lngSize As Long, lngRetVal As Long

lngSize = 199
strBuffer = String$(200, 0)

lngRetVal = GetUserName(strBuffer, lngSize)

GetUser = Left$(strBuffer, lngSize - 1)

End Function
''''module ends''''


You can then call the GetUser() function to return the current user.

Ken Sheridan
Stafford, England
 
D

Douglas J. Steele

I always cringe whenever I see someone suggesting using an Environment
variable to capture user information, given how easy it is to reset
Environment variables for the duration of a database sessions.

The answer Ken suggested is far superior.
 
Top