1
votes

I'm developing a call log system, and for tracking purposes the manager wants each user to be logged in upon entry.

I have a module that displays the current logged on user with the code below. I would like for the system to search the table "TBL_Users" for the username and in the text boxes display all the information pertinent to that username. Should that user not be in the database i need to display an error and not allow the user to progress into the system. I'm aware i may need to use a Dlookup but I'm unsure how to code this.

    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 = vbNullString
    End If
End Function

After playing around with Dlookup for a while, I need the text-boxes to populate on form load. This is the Dlookup i used.

Private Sub Form_Load()

Windows_Logontxt = fOSUserName()

'agentname = DLookup("Agent_Name", "TBL_Users", "Windows_Logon=" & Windows_Logontxt)

End Sub
1
"I'm aware i may need to use a Dlookup but I'm unsure how to code this. " - Everyone is going to be unsure when trying something for the first time, so that is no excuse. Read this and then go ahead and try it anyway. Then come back and edit your question to say "Here is how I tried to use DLookup(): ..." and tell us what happened.Gord Thompson
Edited question above.ASM2701

1 Answers

1
votes

It seems Windows_Logon and Windows_Logontxt are text values, so enclose Windows_Logontxt in quotes when you create the string for the third argument to DLookup.

DLookup("Agent_Name", "TBL_Users", "Windows_Logon='" & Windows_Logontxt & "'")