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

Username Help

Status
Not open for further replies.

Djbell

IS-IT--Management
Apr 22, 2002
175
GB
I have the following function that allows me to get the name of the user that is currently logged into the network, unfortuantly I have just realised this only works for Win 2000 API calls, could any one help me in creating the same function that will run in Win 95, 98 NT & 2000.


Option Compare Database
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

Regards

Djbell
 
DJ,

This is what I use with access 97 and it seems to work fine


Public Declare Function GetUserName Lib &quot;advapi32.dll&quot; Alias &quot;GetUserNameA&quot; (ByVal lpBuffer As String, nSize As Long) As Long

Public Function LogonID() As String

' Determine the currently logged on person's LogonID.

LogonID = Space$(20)
GetUserName LogonID, 20
LogonID = Trim(LogonID)
LogonID = Left$(LogonID, Len(LogonID) - 1)

End Function

best of luck

CRW.
 
Hi BW46263

I have just tried your way but Windows 95 Machines have a problem Running this code, it errors out with a compile error as the database loads.

Regards

Djbell
 
I use the Environ setup... now i use access 2k and win 2k on all systems... but you can try it:

environ(&quot;username&quot;)

try putting this in the imediate window
?environ(&quot;username&quot;)
and see what it comes back with... also try it on a win 95/98 pc befor you impliment it:)

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Sorry Junior1544

But I am not sure what you mean, I have only really started coding in Access.

Regards

Djbell
 
Hi Junior

I figured out the Environ Command it works in 2K, but comes up with Function isn't available in Windows 95.

Regards

Djbell
 
sorry...

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top