UserNameWindows() & UserNameOffice()

  • Thread starter Thread starter George
  • Start date Start date
G

George

why do UserNameWindows() & UserNameOffice() work in Excel but not Access, how
can I get this info?
 
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top