displaying User names on a form

dianafather

New member
Local time
Today, 14:16
Joined
Sep 16, 2008
Messages
1
Hi,
Can anyone help me? I have a table with user names and password. I would like to display Users names on a form as they log in to the database. I am using this getUserName function but it is not working:

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

Function fOSUserName() As String
On Error GoTo fOSUserName_Err

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 = ""
End If


fOSUserName_Exit:
Exit Function

fOSUserName_Err:
MsgBox Error$
Resume fOSUserName_Exit
End Function

Thanks for your support.
Dianafather
 
Hi,
Can anyone help me? I have a table with user names and password. I would like to display Users names on a form as they log in to the database. I am using this getUserName function but it is not working:

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

Function fOSUserName() As String
On Error GoTo fOSUserName_Err

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 = ""
End If


fOSUserName_Exit:
Exit Function

fOSUserName_Err:
MsgBox Error$
Resume fOSUserName_Exit
End Function

Thanks for your support.
Dianafather
emphasis

I use the same function, and I display usernames at the top of every form. I only spotted two differences between your version and mine, (except for the Error handling which I will have to look into using) and have marked them in red. Note that I have no reason to believe that either of them is causing your problems, but I have noted them because they are different from mine, which is displayed below.

Code:
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 [SIZE=4][COLOR=red][B]>[/B][/COLOR][/SIZE] 0) Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = [B][SIZE=4][COLOR=red]vbNullString[/COLOR][/SIZE][/B]
    End If
End Function
 
Last edited:

Users who are viewing this thread

Back
Top Bottom