0

Below is some VBA code to authorize users to login into an MS Access database. I am trying to fix this code and I don’t understand what is the issue in this code snippet.

Private Sub cmdLogin_Click()
Dim lngUserID As Long
    lngUserID = Nz(DLookup("UserID", _
    "tblUser", "username = '" _
    & Me!cbousername _
    & "' AND Password = '" _
    & Me!txtPassword & "'"), 0)
    If lngUserID = 0 Then
        MsgBox "Username and/or password are incorrect."
        Me!txtPassword.SetFocus
    Else
        MsgBox "Registration successful!"
        OptionSetting "CurrentUserID", CStr(lngUserID)
        DoCmd.Close acForm, Me.Name
        DoCmd.OpenForm "Homepage"
    End If
      SetWebControlAsIE9
    ChangeWebControlFeature
END SUB

The debugger in the VBE shows the following code highlighed in yellow. Can someone help me to understand what the issue is?

lngUserID = Nz(DLookup("UserID", _
    "tblUser", "username = '" _
    & Me!cbousername _
    & "' AND Password = '" _
    & Me!txtPassword & "'"), 0)

1 Answer 1

1

Instead of looking for matching username and password from the table, I would suggest you to use login system explained in this link. You just need to import forms and code from demo database from the link into your DB. You'll also get password change form and password reset option. I've use the same approach in my project. I also adopted (recommend you to do too) storing encrypted password approach to prevent user password in case the DB is compromised. If you need any help in that regard too, I'll be happy to help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.