Hi,
I'm trying to set up my database so that when the user logs into my database if their user name and password is in my table it will then open up a certain form; however, if their user name and password is not in my table it will then open up another form. My code doesn't seem to be working and gives me the error message "Too few parameters. Expected 2". I have no idea what is wrong with my code though. Can someone please have a look at it and give me some suggestions why this is not working. Note, some things have been commented out in my code because I've been trying to troubleshoot the problem. I think the problem might have something to do with my SELECT statement though.
Thanks,
Tina.
Private Sub Command5_Click()
On Error GoTo Err_Command5_Click
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Me.txtUserName.SetFocus
'MsgBox txtUserName
'MsgBox txtPassword
Set rs = db.OpenRecordset("SELECT tblUser.User, tblUser.Password FROM tblUser WHERE User = Me.txtUserName AND Password = Me.txtPassword"
'MsgBox "It did the lookup"
If rs.RecordCount <> 1 Then
DoCmd.OpenForm "frmMain_Menu2", acNormal
'MsgBox "There was a match"
Else
DoCmd.OpenForm "frmMain_Menu1", acNormal
'MsgBox "There was NOT a match"
End If
Exit_Command5_Click:
Exit Sub
Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click
End Sub
I'm trying to set up my database so that when the user logs into my database if their user name and password is in my table it will then open up a certain form; however, if their user name and password is not in my table it will then open up another form. My code doesn't seem to be working and gives me the error message "Too few parameters. Expected 2". I have no idea what is wrong with my code though. Can someone please have a look at it and give me some suggestions why this is not working. Note, some things have been commented out in my code because I've been trying to troubleshoot the problem. I think the problem might have something to do with my SELECT statement though.
Thanks,
Tina.
Private Sub Command5_Click()
On Error GoTo Err_Command5_Click
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Me.txtUserName.SetFocus
'MsgBox txtUserName
'MsgBox txtPassword
Set rs = db.OpenRecordset("SELECT tblUser.User, tblUser.Password FROM tblUser WHERE User = Me.txtUserName AND Password = Me.txtPassword"
'MsgBox "It did the lookup"
If rs.RecordCount <> 1 Then
DoCmd.OpenForm "frmMain_Menu2", acNormal
'MsgBox "There was a match"
Else
DoCmd.OpenForm "frmMain_Menu1", acNormal
'MsgBox "There was NOT a match"
End If
Exit_Command5_Click:
Exit Sub
Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click
End Sub