MATU
MATU

Reputation: 11

[Msoft Access]Error with running code for DLookup

I have a problem with Microsoft access for code I have written to lookup the USER TYPE field in the ADMINSTRATOR TABLE.It is not able to run due to syntax error 3075 missing expression operator in query expression 'USER TYPE' It is used for my login menu to differentiate between two different user types and bring them to different forms.

The code works before I implemented the User Security code

Dim UserLevel As Integer 
UserLevel = DLookup("USER TYPE", "ADMINSTRATOR TABLE", "USER ID = '" & Me.txtLoginID & "'")

Here is my code:

 Private Sub Command1_Click()
    Dim UserLevel As Integer

    If IsNull(Me.txtLoginID) Then
        MsgBox "Please enter Login ID", vbInformation, "Login ID Required"
        Me.txtLoginID.SetFocus
    ElseIf IsNull(Me.txtPassword) Then
        MsgBox "Please enter Password", vbInformation, "Password Required"
        Me.txtPassword.SetFocus
    Else
    If (IsNull(DLookup("[User ID]", "ADMINSTRATOR TABLE", "[User ID]='" & Me.txtLoginID.Value & "' And Password = '" & Me.txtPassword.Value & "'"))) Then
        MsgBox "Incorrect Password or Login ID", vbInformation, "Login unsuccessful"
        Else
        UserLevel = DLookup("USER TYPE", "ADMINSTRATOR TABLE", "USER ID = '" & Me.txtLoginID & "'")
           DoCmd.Close
            If UserLevel = 1 Then
             MsgBox "Login Success", vbInformation, "Login Success"
             DoCmd.OpenForm "MAIN MENU"
           Else
           MsgBox "Login Success", vbInformation, "Login Success"
           DoCmd.OpenForm "ADMINISTRATOR FORM"
    End If
    End If
    End If
    End Sub

Upvotes: 0

Views: 39

Answers (1)

AVG
AVG

Reputation: 1462

Field names and table names containing spaces or special characters (poor design choice) need to surrounded with square brackets.

Upvotes: 1

Related Questions