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

Using AP get UserName in access 2K 1

Status
Not open for further replies.

brightstar

Technical User
Sep 20, 2002
233
OK, Ive converted and Access 97 db into 2K. But now my function that identifies the current logged on user doesnt see to work. its an API called advapi32.dll i think. here it is:

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

Function ap_GetUserName() As String

' Declare Variables
Dim strUserName As String
Dim lngLength As Long
Dim lngResult As Long

' Set up the buffer
strUserName = String$(255, 0)
lngLength = 255

' Make the call
lngResult = wu_GetUserName(strUserName, lngLength)

' Assign the value
ap_GetUserName = Left(strUserName, 8)

End Function

normally this would give you the username, on our NT network, but on the NT laptop it gives |||||||||||||||.
any ideas how i can fix it?
 
on an NT network, you can use
myUser = environ("username")
to get the same information - however, both methods are unreliable if the laptop is not connected to the network Rgds
Geoff

Vah! Denuone Latine loquebar? Me ineptum. Interdum modo elabitur
 
so is there any way of recovering the logged on username on a stand alone laptop? even if it is "administrator" or "User", surely the API should still return something?
 
You could try the environ("username") - I have not tested on a standalone pc - that was from something I read - it may be that the unreliable effect is that it returns "administrator" or something - worth a try tho
Rgds
Geoff

Vah! Denuone Latine loquebar? Me ineptum. Interdum modo elabitur
 
it does return administrator or whatever username you have used - but at least there's about 15 lines less code in that way of doing it than in mine and it has the disired effect.

cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top