Hi,
I've created a login form based on a Users table. My intention is for the user to type in their username/password and the VBA is supposed to loop through the table until that username/password record is reached. Once the username/password is verified, the app is supposed to Open an Approval form. However, I keep getting an error message. Can some please help. The code is as follows:
Dim rs As ADODB.Recordset
rs.ActiveConnection =
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=\\intraweb\" & _
"CapitalProjects$\CapitalProjects.mdb;"
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM Users;"
rs.MoveFirst
Do
Debug.Print rs.Fields(0), rs.Fields(1)
If rs.EOF = True Or rs.BOF = True Then
Exit Sub
End If
If Not txtUserName.Value > "" Or
(Not txtPassword.Value > "") Then
MsgBox "You cannot enter a blank
Username/Password. Try again."
txtUserName.SetFocus
Exit Sub
ElseIf UserName = txtUserName.Value And
Password = txtPassword.Value Then
MsgBox "You are logged in as " & UserName
stDocName = "Approval"
stDocName2 = "Login"
DoCmd.Close acForm, "Login"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit Sub
End If
rs.MoveNext
Loop
If txtUserName.Value <> UserName Or
txtPassword.Value <> Password Then
MsgBox "You are not authorized to access this form!"
MsgBox UserName
stDocName = "Selection"
stDocName2 = "Login"
DoCmd.Close acForm, "Login"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit Sub
End If
rs.Close
Set rs = Nothing
I've created a login form based on a Users table. My intention is for the user to type in their username/password and the VBA is supposed to loop through the table until that username/password record is reached. Once the username/password is verified, the app is supposed to Open an Approval form. However, I keep getting an error message. Can some please help. The code is as follows:
Dim rs As ADODB.Recordset
rs.ActiveConnection =
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=\\intraweb\" & _
"CapitalProjects$\CapitalProjects.mdb;"
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM Users;"
rs.MoveFirst
Do
Debug.Print rs.Fields(0), rs.Fields(1)
If rs.EOF = True Or rs.BOF = True Then
Exit Sub
End If
If Not txtUserName.Value > "" Or
(Not txtPassword.Value > "") Then
MsgBox "You cannot enter a blank
Username/Password. Try again."
txtUserName.SetFocus
Exit Sub
ElseIf UserName = txtUserName.Value And
Password = txtPassword.Value Then
MsgBox "You are logged in as " & UserName
stDocName = "Approval"
stDocName2 = "Login"
DoCmd.Close acForm, "Login"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit Sub
End If
rs.MoveNext
Loop
If txtUserName.Value <> UserName Or
txtPassword.Value <> Password Then
MsgBox "You are not authorized to access this form!"
MsgBox UserName
stDocName = "Selection"
stDocName2 = "Login"
DoCmd.Close acForm, "Login"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit Sub
End If
rs.Close
Set rs = Nothing