I am getting 2 problems what I am trying to do is depending on the user loging in I want to open form (Aform) on specific record for that person ID. However where Y=1 I am getting a popup asking for AForm ID and where Y=2 I am getting run time error 3075 Syntax error (missing operator) in query expression.
Code:
Private Sub Command6_Click()
If IsNull(txtUsername) Then
MsgBox "Invalid username"
Exit Sub
End If
If IsNull(txtPassword) Then
MsgBox "Invalid password"
Exit Sub
End If
Dim X As Long
Dim SQL As String
X = Nz(DLookup("UserID", "UserT", "Username='" & txtUsername & "' AND Password='" & txtPassword & "'"))
'MsgBox "" & X & ""
If X > 0 Then
Dim Y As Long
Y = Nz(DLookup("GroupID", "GroupXUsersT", "UserID='" & X & "'"))
'MsgBox "" & Y & ""
'We have a valid user
If Y = 1 Then
DoCmd.OpenForm "MainMenu"
DoCmd.OpenForm "AForm", acNormal, , "[AID] = " & txtUsername
Forms!MainMenu!txtUserID = X
Forms!MainMenu!txtUsername = txtUsername
Forms!AForm!txtUserID = X
Forms!AForm!txtUsername = txtUsername
DoCmd.Close acForm, "LoginF"
End If
If Y = 2 Then
DoCmd.OpenForm "MainMenu"
DoCmd.OpenForm "NewHireFeedbackForm", acNormal, , "[NewHireID] = " & txtUsername
Forms!MainMenu!txtUserID = X
Forms!MainMenu!txtUsername = txtUsername
Forms!NewHireFeedbackForm!txtUserID = X
Forms!NewHireFeedbackForm!txtUsername = txtUsername
DoCmd.Close acForm, "LoginF"
End If
Else
MsgBox "Invalid Logon"
End If
End Sub