justin0312
New member
- Local time
- Tomorrow, 05:09
- Joined
- Jul 2, 2021
- Messages
- 22
Hi, I made some minor changes to my login form and I am having a problem when user key in invalid username/password, it will prompt me an error message (run-time error '3201': No current record.)
I tried testing with the followings
correct username, password and account is active, is working
correct username incorrect password and account is active, is working
correct username, password and account is inactive, is working
incorrect username, password, prompt me the error message
My table have this fields
ID | username | password | account status
I cannot figure out where is the issues. The error keep point to this line
Hope someone can help me.
I tried testing with the followings
correct username, password and account is active, is working
correct username incorrect password and account is active, is working
correct username, password and account is inactive, is working
incorrect username, password, prompt me the error message
My table have this fields
ID | username | password | account status
I cannot figure out where is the issues. The error keep point to this line
Code:
If rst!password = Encrypt(Me.password) And rst![account status].value = "Inactive" Then
Hope someone can help me.
Code:
Private Sub login_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim sql As String
If Trim(Me.username.value & vbNullString) = vbNullString Then
MsgBox prompt:="Please enter username.", buttons:=vbInformation, title:="Information Required"
Me.username.SetFocus
Exit Sub
End If
If Trim(Me.password.value & vbNullString) = vbNullString Then
MsgBox prompt:="Please enter password.", buttons:=vbInformation, title:="Information Required"
Me.password.SetFocus
Exit Sub
End If
sql = "Select password, [security level], [account status] FROM tbl_db_user WHERE Username = '" & Me.username.value & "'"
Set db = CurrentDb
Set rst = db.OpenRecordset(sql)
If rst!password = Encrypt(Me.password) And rst![account status].value = "Inactive" Then
MsgBox prompt:="Account already inactive.", buttons:=vbCritical, title:="Error"
Else
If rst!password = Encrypt(Me.password) Then
MsgBox prompt:="Welcome", buttons:=vbOKOnly, title:="Logon"
Else
MsgBox prompt:="Your username/password is incorrect.", buttons:=vbCritical, title:="Error"
End If
End If
Set db = Nothing
Set rst = Nothing
End Sub