Getting NT User Login Names from Access 2000 or 2003

  • Thread starter Thread starter Guest
  • Start date Start date
John: As I've pointed out before in this thread, you're incorrect.

The value of lngLen gets reset by the API call. In other words, it should
NOT be 255 after the call.

The code Michael's using comes from
http://www.mvps.org/access/api/api0008.htm at "The Access Web", and it works
as advertised.
 
Since you're getting 0s, you can use the code as I wrote it.

What I was trying to say is that, say you were getting

8: (7)
9: (7)
10: (7)

then you'd use

fOSUserName = Left$(strUserName, InStr(fOSUserName, Chr(7)) - 1)
 
Douglas J. Steele said:
John: As I've pointed out before in this thread, you're incorrect.

The value of lngLen gets reset by the API call. In other words, it should
NOT be 255 after the call.

Hi Douglas

I say all that in my last post.

The error in the original code is Michael passing an EXPRESSION *not* lngLen
to the api call.
see the line ending "lngLen - 1) ' <-- Error Here".

It's the (minus) (One) that's stopping lngLen from being updated.


Regards John
 
John Griffiths said:
Hi Douglas

I say all that in my last post.

The error in the original code is Michael passing an EXPRESSION *not*
lngLen
to the api call.
see the line ending "lngLen - 1) ' <-- Error Here".

It's the (minus) (One) that's stopping lngLen from being updated.

My apology: you're right.
 
Hi John and Doug,
I just sent you a reply but of course I got a 'could not find page' error on
my posting.

I tried John's final suggestion,
should read
lngX = apiGetUserName(strUserName, lngLen)
and now the fosusername function returns my username + 1 box, so we're
gettin' somewhere. A Trim also still shows (hovering and locals window) my
name + the 1 box.

Any ideas?
 
Michael Miller said:
Hi John and Doug,
I just sent you a reply but of course I got a 'could not find page' error on
my posting.

I tried John's final suggestion,
should read
lngX = apiGetUserName(strUserName, lngLen)
and now the fosusername function returns my username + 1 box, so we're
gettin' somewhere. A Trim also still shows (hovering and locals window) my
name + the 1 box.

Any ideas?

fOSUserName = Left(strUserName, lngLen-1)

:-)

John


=========================================
' My version of your code after interjection by Douglas
'
Public Function fOSUserName() As String
'---------------------------------
'returns the network login name
'---------------------------------
Dim lngLen As Long
Dim lngX As Long
Dim strUserName As String

lngLen = 255 ' max allowed from api, from max filename length FAT32
strUserName = Space(lngLen)
lngX = apiGetUserName(strUserName, lngLen)
'---------------------------------
' lngX = api result
' lngLen = number of characters replaced including final Chr(0)

If (lngX > 0) Then
fOSUserName = Left(strUserName, lngLen-1)
Else
fOSUserName = vbNullString
End If
'---------------------------------
End Function
=========================================
 
John,
Are you saying that I have to go back to lngLen-1?
I thought that was returning all those boxes?
Do you mean there's nothing else I can try, although you do have Left
without the "$", but I don't know if you wanted me to try that.
 
Back
Top