I am creating a login system for a helpdesk database and was advised that this following code would help:
Private Sub cmdEnter_Click()
'This procedure will check the password with the name and
'will open the main menu if they match. If no match occurs
'after three tries Access is exited
'Declare local variables
Dim dbsTestbase As DAO.Database
Dim rstUsers As DAO.Recordset
Dim UserName As String
Dim UserPassword As String
'Validate existance of information on the form
If Nz(Len(txtName), 0) = 0 Then
Call MsgBox("You must enter a name", vbOKOnly + vbInformation _
, "No Name Entered")
Call txtName.SetFocus
GoTo ExitSub
End If
If Nz(Len(txtPassword), 0) = 0 Then
Call MsgBox("You must enter a password", vbOKOnly + vbInformation _
, "No Password Entered")
Call txtPassword.SetFocus
GoTo ExitSub
End If
'Set object variables
Set dbsTestbase = CurrentDb
Set rstUsers = dbsTestbase.OpenRecordset("tblUsers", dbOpenDynaset)
'Store form information in local variables
UserName = txtName
UserPassword = txtPassword
'Test for name and password match
rstUsers.FindFirst "fldUserName = " & Quote & UserName & Quote
If rstUsers.NoMatch Then
Call MsgBox("The name you have entered is not in the official " & _
"users file. Try entering the name again. If you " & _
"are sure the name is correct, exit Access and call " & _
"the system administrator", vbInformation, "Name not Matched")
Call txtName.SetFocus
fTries = fTries + 1
Else
If rstUsers!fldUserPassword = UserPassword Then
Select Case rstUsers!fldAccessLevel
Case "User"
'Open users form'
Case "Manager"
'Open managers form'
End Select
frmUserID!txtUserID = UserName
Else
Call MsgBox("The password you have entered does not match " & _
"the name you entered. Please re-enter the " & _
"password. If you are sure the password you " & _
"entered is correct, please call your system " & _
"administrator", vbInformation, "Password Incorrect")
Call txtPassword.SetFocus
fTries = fTries + 1
End If
End If
ExitSub:
I have a table called "tblUsers" with the fields "UserName", "UserPassword" and "AccessLevel". I also have a login form with "txtName" and "txtPassword" fields and a "cmdEnter" and "cmdExit" button. The problem is that when i run the code I get a Run Time Error 3070, The Jet Database Engine does not recognise 'fldUserName' as a valid field name or expression with regards to the "Testing for name and password match" section of the code. Does anyone know what I am doing wrong, how to resolve this or what the fld prefix actually means?
I also required the database to open a different form dependent upon whether the "AccessLevel" of the user was "Manager" or "User". Where it says Case "User" in the code do I have to add a line to open the relevant form and if so how?
Thanks in advance!
Private Sub cmdEnter_Click()
'This procedure will check the password with the name and
'will open the main menu if they match. If no match occurs
'after three tries Access is exited
'Declare local variables
Dim dbsTestbase As DAO.Database
Dim rstUsers As DAO.Recordset
Dim UserName As String
Dim UserPassword As String
'Validate existance of information on the form
If Nz(Len(txtName), 0) = 0 Then
Call MsgBox("You must enter a name", vbOKOnly + vbInformation _
, "No Name Entered")
Call txtName.SetFocus
GoTo ExitSub
End If
If Nz(Len(txtPassword), 0) = 0 Then
Call MsgBox("You must enter a password", vbOKOnly + vbInformation _
, "No Password Entered")
Call txtPassword.SetFocus
GoTo ExitSub
End If
'Set object variables
Set dbsTestbase = CurrentDb
Set rstUsers = dbsTestbase.OpenRecordset("tblUsers", dbOpenDynaset)
'Store form information in local variables
UserName = txtName
UserPassword = txtPassword
'Test for name and password match
rstUsers.FindFirst "fldUserName = " & Quote & UserName & Quote
If rstUsers.NoMatch Then
Call MsgBox("The name you have entered is not in the official " & _
"users file. Try entering the name again. If you " & _
"are sure the name is correct, exit Access and call " & _
"the system administrator", vbInformation, "Name not Matched")
Call txtName.SetFocus
fTries = fTries + 1
Else
If rstUsers!fldUserPassword = UserPassword Then
Select Case rstUsers!fldAccessLevel
Case "User"
'Open users form'
Case "Manager"
'Open managers form'
End Select
frmUserID!txtUserID = UserName
Else
Call MsgBox("The password you have entered does not match " & _
"the name you entered. Please re-enter the " & _
"password. If you are sure the password you " & _
"entered is correct, please call your system " & _
"administrator", vbInformation, "Password Incorrect")
Call txtPassword.SetFocus
fTries = fTries + 1
End If
End If
ExitSub:
I have a table called "tblUsers" with the fields "UserName", "UserPassword" and "AccessLevel". I also have a login form with "txtName" and "txtPassword" fields and a "cmdEnter" and "cmdExit" button. The problem is that when i run the code I get a Run Time Error 3070, The Jet Database Engine does not recognise 'fldUserName' as a valid field name or expression with regards to the "Testing for name and password match" section of the code. Does anyone know what I am doing wrong, how to resolve this or what the fld prefix actually means?
I also required the database to open a different form dependent upon whether the "AccessLevel" of the user was "Manager" or "User". Where it says Case "User" in the code do I have to add a line to open the relevant form and if so how?
Thanks in advance!