Hi,
I'm new to Access or as a matter of fact it's the first time that I'm working with a database. I'm working on a program in Access for a class project and I'm having some trouble with the login application. The program is basically a database for a small store which allows the employees to login with or without administrator access. The usename and password for each employee is stored in tblEmployee under strUseName and strPassword. The table also contains a ysnAdmin checkbox. (The ysnAdmin boolean variable is declared globally since it is also called from frmMain.)The problem I'm having is that when I try to do the rst.FindFirst it works if the password and username I enter are incorrect and the record is not found but when I enter a password and username that is stored in the tblEmployee I get a Type error message. I would really appreciate if somebody could look at this code and tell me what I'm doing wrong.
I'm new to Access or as a matter of fact it's the first time that I'm working with a database. I'm working on a program in Access for a class project and I'm having some trouble with the login application. The program is basically a database for a small store which allows the employees to login with or without administrator access. The usename and password for each employee is stored in tblEmployee under strUseName and strPassword. The table also contains a ysnAdmin checkbox. (The ysnAdmin boolean variable is declared globally since it is also called from frmMain.)The problem I'm having is that when I try to do the rst.FindFirst it works if the password and username I enter are incorrect and the record is not found but when I enter a password and username that is stored in the tblEmployee I get a Type error message. I would really appreciate if somebody could look at this code and tell me what I'm doing wrong.
Code:
Private Sub cmd_Login_Click() Dim rst As DAO.Recordset Dim strUser As String Dim strPass As String Dim strSQL As String If Me.txtUserName = "" Or IsNull(Me.txtUserName) Then MsgBox "Please enter a valid User Name", vbExclamation, strApp Me.txtUserName.SetFocus Exit Sub ElseIf Me.txtPassword = "" Or IsNull(Me.txtPassword) Then MsgBox "Please enter a valid password", vbExclamation, strApp Me.txtPassword.SetFocus Exit Sub End If strUser = Me.txtUserName strPass = Me.txtPassword strSQL = "SELECT tblEmployee.strUserName, tblEmployee.strPassword, tblEmployee.ysnAdmin FROM tblEmployee WHERE (((tblEmployee.strUserName)='" & strUser & "') AND ((tblEmployee.strPassword)='" & strPass & "'))" Set rst = CurrentDb.OpenRecordset(strSQL) rst.FindFirst (strSQL) '([I]Type error message[/I]) If rst.NoMatch Then MsgBox ("Access Denied") Else If Not rst.EOF Then If rst!ysnAdmin = True Then ysnAdmin = True Else ysnAdmin = False End If End If End If rst.Close Set rst = Nothing DoCmd.Close acForm, Me.Name End Sub
Comment