Display Windows Log On Name

Cosmicnoodle

Registered User.
Local time
Today, 11:45
Joined
Jun 14, 2005
Messages
33
Is it possible to display the user name used to log on to windows on a form?
I have used the following code to get the machine name to display - but some machines are old and have new users.....

Private Declare Function apiGetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSMachineName() As String
Dim lngLen As Long, lngX As Long
Dim strCompName As String

lngLen = 16
strCompName = String$(lngLen, 0)
lngX = apiGetComputerName(strCompName, lngLen)
If lngX <> 0 Then
fOSMachineName = Left$(strCompName, lngLen)
Else
fOSMachineName = ""
End If

End Function

Then use =fOSMachineName() in a label


Any idea?
 
Throw that old funciton in the trash. Use Environ("ComputerName") instead.

Environ("UserName") will work for all versions of Access and Windows to grab the users network name. Search around for I have posted a sample db that will list all of the options you can extract from a users computer with the Environ() function.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom