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

How do I get the Users ID in WIN 98?

Status
Not open for further replies.

polsterd

Technical User
Feb 19, 2002
2
ES
This code is executed at open of a form in Access 97. An error appears on the win 98 machines but does not appear on the NT machines. The error is the one in the code because it is not finding the username. I have searched archived items and I was able to get the code working on win 95 by adding a statement to the autoexec.bat file. The statement was "set UserName=%username%". This did not work on WIN 98. I am looking for a simple solution to obtain the logged in user on a win 98 machine.

What should I add to this code or any other ideas?

Thanks

-------Code Begin--------

Private Sub Form_Load()

Dim EmployeeID As String
'
' Get employee ID from environment variable:
'

EmployeeID = Environ("USERNAME")
If EmployeeID = "" Then
EmployeeID = Environ("UserID")
End If
If EmployeeID = "" Then
MsgBox "Could not get UserID from system. Some functions may not be available", vbExclamation, "Warning!"
Else
Me![Employee ID] = EmployeeID
End If
DoCmd.Maximize
End Sub
--------Code End--------
 
Try adding this function to a module and calling it. I haven't tried it on Win2000, but it does work on Win98.

This is from Dev Ashish's very useful site:
Code:
'******************** Code Start **************************
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
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
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = &quot;&quot;
    End If
End Function

'******************** Code End **************************
----------------------------------------------
© 1998-2000, Dev Ashish, All rights reserved
 
Have you tried typing the &quot;SET&quot; command at the C: prompt to see what system variables are already set?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top