User Reset Password .vba

mba_110

Registered User.
Local time
Yesterday, 16:06
Joined
Jan 20, 2015
Messages
280
Hi everyone,

I am doing a small exercise within my DB to initiate user logins and reset password forms.

I have following code in password reset form but its not a correct one but some how i able to reach half way.

This exercise to reset users login detail if in case they forgot the password.

I have three buttons (BtnSubmitLoginID, BtnCancel, BtnResetPassword)

Step 1: I want if LoginID text box is blank then following message asking to enter the correct LoginID should appear.

Step 2 : Next is once loginID is filled with data it should check tblUsers for this user's LoginID if found then remaining next two fields (txtEmpID & txtPrevillage) should appear on the form, otherwise it should ask to enter correct loginID.

Step 3: After this user's next step should be filling the information in txtEmpID and txtPrevillage if its goes wrong the same message should appear asking to enter correct details, otherwise the 3 security questions combobox (cboQuestion1, cboQuestion2, cboQuestion3) should should appear/filled with user's saved questions in tbluser.

Step 4: After above if answers where given wrongly for 3 attempts then it should not further allow user to Reset password manual and give message to contact the Administrator, if answered correctly while attempting three times for all answers than he could be able to reset the necessary questions and all the other details with reset Button.


Code:
 Option Compare Database

Private Sub BtnCancel_click()
Me.Undo
DoCmd.Close
End Sub

Private Sub BtnResetPassword_Click()

End Sub

Private Sub BtnSubmitLoginID_Click()
On Error GoTo errhandlers:
If IsNull(LoginID) Then
    MsgBox "You have not entered Login ID", , "No info"
ElseIf IsNull(txtEmpID) Or IsNull(txtPrevillage) Or IsNull(txtAnswer1) Or IsNull(txtAnswer2) Or IsNull(txtAnswer3) Then
    MsgBox "Employee ID, Previllage & All Answer fields are required !", , "Required fields"
Else
    msg = "Do you want to submit your information"
    Style = vbYesNo + vbCritical
    Title = "Registration Confirmed"
    response = MsgBox(msg, Style, Title)
    If response = vbYes Then
        DoCmd.Close
        Exit Sub
    End If
    If response = vbNo Then
        Me.Undo
        DoCmd.Close
        Exit Sub
    End If
End If
exit_errhandlers:
Exit Sub
errhandlers:
    MsgBox Err.Description, vbCritical
    Err.Clear
    Exit Sub
End Sub


I can feel it could be extensive coding but your generous help will be appreciated.
 
I have a couple of suggestions that might help.

Note that some consider this poor style but I recommend using exit sub when you are done checking a particular condition rather than have a long if - esleif else statement. For example:

Code:
If IsNull(LoginID) Then
    MsgBox "You have not entered Login ID", , "No info"
    Exit Sub
End If

If .....

You can use DLookUp to retrieve information from the tblUser. Something many don't know is that if you use the full form reference in the criteria you don't have to concatenate the form control value (textbox) in. That avoids a crap load of problems. So I suggest doing something like this:

Code:
If Me.txtAnswer1 <> DLookUp("[Answer1]", "[tblUsers]", "[EmpID] = [Forms]![TheNameOfTheForm]![txtEmpID]" Then
''do something

over
Code:
If Me.txtAnswer1 <> DLookUp("[Answer1]", "[tblUsers]", "[EmpID] = '" & Me.txtEmpID & "'" Then
''do something

Note that there are a lot of assumptions about how you are naming things in that code example so please understand that's it's just an example.

Another way and perhaps better way to access the tblUser data is just to open a recordset. Once open then you have access to all of the data in the record. Let's say you have:


Code:
Private Sub BtnSubmitLoginID_Click()

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("Select * FROM tblUsers WHERE [EmpID] = '" & Me.txtEmpID & "'")
If rs.EOF And rs.BOF Then
    MsgBox "User not found"
    Exit Sub
End If
Debug.Print rs!Answer1
rs.Close

End Sub

Unfortunately the concatenation of the form control cannot be easily avoided in this scenario and in this case EmpID is assumed to be text. Nonetheless you can access any of the fields in the tblUsers record with the format rs!FieldName. In this code the Answer1 field is displayed in the Immediate window.

The reason why this might be better for you is that you need to have a loop variable with the number of retries. With the recordset open like this it would be easy just to have it as one of the fields rather than in a global variable. Let say the name of the field was Retries. You could update that in the loop with some like.
Code:
rs.Edit
rs!Retries = rs!Retries - 1
rs.Update
 
Last edited:
mba_110

You want the question combos to come up in the event of an invalid login entry.

But before the combos are displayed, your code is testing the answers
Code:
ElseIf IsNull(txtEmpID) Or IsNull(txtPrevillage) Or IsNull(txtAnswer1) Or IsNull(txtAnswer2) Or IsNull(txtAnswer3) Then

Follow your written logic ie don't try to combine Steps 2 and 3 into one line of code.
 
A lot of points are missing in my coding, i can understand that i am asking too much from you guys but i am still learner and interested in programming.

Now the situation is,

Step 1 : This step have ok with first portion of coding if blank but second portion of code to see whether this user exist or not is not working and giving error.

Private Sub BtnSubmitLoginID_Click()
If IsNull(txtLoginID) Or txtLoginID = "" Then
MsgBox "You have not entered Login ID", , "No info"
Me.txtEmpID.Visible = False
Me.txtPrevillage.Visible = False
Me.cboQuestion1.Visible = False
Me.cboQuestion2.Visible = False
Me.CboQuestion3.Visible = False
Me.txtAnswer1.Visible = False
Me.txtAnswer2.Visible = False
Me.txtAnswer3.Visible = False
Me.BtnCancel.Visible = False
Me.BtnResetPassword.Visible = False
Else
Me.txtEmpID.Visible = True
Me.txtPrevillage.Visible = True

End If
End Sub


Step 2: The Fields on form (txtEmpID & txtPrevillage) should not appear if txtLoginID is not completely verified and confirmed.


Step 3: After this user's next step should be filling the information in txtEmpID and txtPrevillage if its goes wrong the same message should appear asking to enter correct details, otherwise the 3 security questions combobox (cboQuestion1, cboQuestion2, cboQuestion3) should should appear/filled with user's saved questions in tbluser.


Step 4: After above if answers where given wrongly for 3 attempts then it should not further allow user to Reset password manual and give message to contact the Administrator, if answered correctly while attempting three times for all answers than he could be able to reset the necessary questions and all the other details with reset Button.

I have some how manage the below as per your guidance but don't know the exact coding to accomplished the task.

Private Sub BtnResetPassword_Click()
If IsNull(txtEmpID) Then
MsgBox "You have not entered Employee ID", , "No info"

If IsNull(txtPrevillage) Then
MsgBox "You have not entered User Previllage", , "No Info"

If IsNull(txtAnswer1) Or (txtAnswer2) Or (txtAnswer3) Then
MsgBox "You have not Answer all security questions", , "No Info"

DoCmd.OpenForm "frmResetPassword", acNormal, , "[LoginID] = " & Me.txtLoginID
End If

End Sub



The Full Code is as per following.

Option Compare Database

Private Sub BtnCancel_click()
Me.Undo
DoCmd.Close
End Sub

Private Sub BtnResetPassword_Click()
If IsNull(txtEmpID) Then
MsgBox "You have not entered Employee ID", , "No info"
end if
end sub

If IsNull(txtPrevillage) Then
MsgBox "You have not entered User Previllage", , "No Info"
end if
end sub

If IsNull(txtAnswer1) Or (txtAnswer2) Or (txtAnswer3) Then
MsgBox "You have not Answer all security questions", , "No Info"
end if
end sub

DoCmd.OpenForm "frmResetPassword", acNormal, , "[LoginID] = " & Me.txtLoginID
End If

End Sub

Private Sub BtnSubmitLoginID_Click()
If IsNull(txtLoginID) Or txtLoginID = "" Then
MsgBox "You have not entered Login ID", , "No info"
Me.txtEmpID.Visible = False
Me.txtPrevillage.Visible = False
Me.cboQuestion1.Visible = False
Me.cboQuestion2.Visible = False
Me.CboQuestion3.Visible = False
Me.txtAnswer1.Visible = False
Me.txtAnswer2.Visible = False
Me.txtAnswer3.Visible = False
Me.BtnCancel.Visible = False
Me.BtnResetPassword.Visible = False
Else
Me.txtEmpID.Visible = True
Me.txtPrevillage.Visible = True

End If
End Sub


Step 5 : Now when the reset button is successfully commanded than frmResetpassword should be open specifically for user on his user ID to do change their login details, but this form has an issue of duplicating the combo boxes question selection i mean, their is 3 combo box and each is bounded to tblQuestions and row source is SELECT DISTINCT tblQuestions.Questions FROM tblQuestions;
now i want if cboquestion-1 is selected the question it should not appear again in next two question's combo boxes value and same should happen for 2 and 3 combo boxes all three questions should be unique and not duplicate.

Thanks & regards,

MBA
 
Last edited:
That is not the "full code".
Code:
Private Sub BtnResetPassword_Click()
If IsNull(txtEmpID) Then
MsgBox "You have not entered Employee ID", , "No info"

If IsNull(txtPrevillage) Then
MsgBox "You have not entered User Previllage", , "No Info"

If IsNull(txtAnswer1) Or (txtAnswer2) Or (txtAnswer3) Then
MsgBox "You have not Answer all security questions", , "No Info"

DoCmd.OpenForm "frmResetPassword", acNormal, , "[LoginID] = " & Me.txtLoginID
End If

End Sub
Three ifs and one endif. You need to add after the message in each case, exit sub and endif.
 
I don't have one i want to complete it, the requirement i already mentioned in my previous messages and all related field names and tables/forms.

Here is modified code:

Code:
Private Sub BtnCancel_click()
Me.Undo
DoCmd.Close
End Sub

Private Sub BtnResetPassword_Click()
On Error GoTo ErrorHandler:

'Check to see Employee ID is entered correctly in to the txtEmpID (Case Sensitive).
    If IsNull(Me.txtEmpID) Or Me.txtEmpID = "" Then
    MsgBox "You must enter a correct Employee ID.", vbOKOnly, "Invalid Entry!"
    Me.txtEmpID.SetFocus
    End If

If Me.txtEmpID.Value = DLookup("EmpID", "tblUsers", _
            "[UserID]=" & Me.txtEmpID.Value) Then

        UserID = Me.txtEmpID.Value
        DoCmd.Close acForm, "frmuserpasswordRe-set", acSaveNo
        
    Else
      MsgBox "Invalid Employee ID. Please Try Again", vbOKOnly, _
            "Invalid Entry!"
        Me.txtEmpID.SetFocus
    End If


'Check to see Previllage is entered correctly in to the txtPrevillage (Case Sensitive).

    If IsNull(Me.txtPrevillage) Or Me.txtPrevillage = "" Then
    MsgBox "You must enter a correct User Previllage.", vbOKOnly, "Invalid Entry!"
    Me.txtPrevillage.SetFocus
    End If

If Me.txtPrevillage.Value = DLookup("Previllage", "tblUsers", _
            "[UserID]=" & Me.txtPrevillage.Value) Then

        UserID = Me.txtPrevillage.Value
        DoCmd.Close acForm, "frmuserpasswordRe-set", acSaveNo
        
    Else
      MsgBox "Invalid Previllage Input. Please Try Again", vbOKOnly, _
            "Invalid Entry!"
        Me.txtPrevillage.SetFocus
    End If


'Check to see if data is entered into the password textbox.

    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
      MsgBox "You must enter a Password.", vbOKOnly, "Invalid Entry!"
        Me.txtPassword.SetFocus
        Exit Sub
    
        
    End If
    
    
'Check value of password in tblUsers to see if this matches value entered in txtPassword (Case Sensitive).

    If Me.txtPassword.Value = DLookup("StrPassword", "tblUsers", _
            "[UserID]=" & Me.txtPassword.Value) Then

        UserID = Me.txtPassword.Value
        DoCmd.Close acForm, "frmuserpasswordRe-set", acSaveNo
        
    Else
      MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
            "Invalid Entry!"
        Me.txtPassword.SetFocus
    End If
    
'If User Enters incorrect password 3 times database will shutdown.

    intLogonAttempts = intLogonAttempts + 1
    If intLogonAttempts > 3 Then
      MsgBox "You do not have access to this database.Please contact Administrator.", _
               vbCritical, "Restricted Access!"
        Application.Quit
    End If
    
'Check to see Question - 1 is answered correctly (Case Sensitive).
    If IsNull(Me.txtAnswer1) Or txtAnswer1 = "" Then
    MsgBox "You must enter a correct answers for security question!.", vbOKOnly, "Invalid Entry!"

    End If

If Me.txtAnswer1.Value = DLookup("Answer-1", "tblUsers", _
            "[UserID]=" & Me.txtAnswer1.Value) Then

        UserID = Me.txtAnswer1.Value
        DoCmd.Close acForm, "frmuserpasswordRe-set", acSaveNo
        
    Else
      MsgBox "Incorrect Answer. Please Try Again", vbOKOnly, _
            "Invalid Entry!"
        Me.txtAnswer1.SetFocus
    End If

'Check to see Question - 2 is answered correctly (Case Sensitive).
    If IsNull(Me.txtAnswer2) Or txtAnswer2 = "" Then
    MsgBox "You must enter a correct answers for security question!.", vbOKOnly, "Invalid Entry!"

    End If

If Me.txtAnswer2.Value = DLookup("Answer-2", "tblUsers", _
            "[UserID]=" & Me.txtAnswer2.Value) Then

        UserID = Me.txtAnswer2.Value
        DoCmd.Close acForm, "frmuserpasswordRe-set", acSaveNo
        
    Else
      MsgBox "Incorrect Answer. Please Try Again", vbOKOnly, _
            "Invalid Entry!"
        Me.txtAnswer2.SetFocus
    End If

'Check to see Question - 3 is answered correctly (Case Sensitive).
    If IsNull(Me.txtAnswer3) Or txtAnswer3 = "" Then
    MsgBox "You must enter a correct answers for security question!.", vbOKOnly, "Invalid Entry!"

    End If

If Me.txtAnswer3.Value = DLookup("Answer-3", "tblUsers", _
            "[UserID]=" & Me.txtAnswer3.Value) Then

        UserID = Me.txtAnswer3.Value
        DoCmd.Close acForm, "frmuserpasswordRe-set", acSaveNo
        
    Else
      MsgBox "Incorrect Answer. Please Try Again", vbOKOnly, _
            "Invalid Entry!"
        Me.txtAnswer3.SetFocus
    End If

ErrorHandler:

End Sub

Private Sub BtnSubmitLoginID_Click()
On Error GoTo ErrorHandler:

'Check to see if data is entered into the txtLoginID text box.

If IsNull(Me.txtLoginID) Or txtLoginID = "" Then
    MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
    Me.txtLoginID.SetFocus
    Me.txtEmpID.Visible = False
    Me.txtPassword.Visible = False
    Me.txtPrevillage.Visible = False
    Me.txtQuestion1.Visible = False
    Me.txtQuestion2.Visible = False
    Me.txtQuestion3.Visible = False
    Me.txtAnswer1.Visible = False
    Me.txtAnswer2.Visible = False
    Me.txtAnswer3.Visible = False
    Me.BtnCancel.Visible = False
    Me.BtnResetPassword.Visible = False
Else
   Me.txtEmpID.Visible = True
    Me.txtPrevillage.Visible = True
    Me.txtPassword.Visible = True
End If


'Check to see Login ID provided are correct or not with tblUser (Case Sensitive).

If Me.txtLoginID.Value = DLookup("LoginID", "tblUsers", _
            "[UserID]=" & Me.txtLoginID.Value) Then

        UserID = Me.txtLoginID.Value
        DoCmd.Close acForm, "frmuserpasswordRe-set", acSaveNo
        
    Else
      MsgBox "Invalid Login ID. Please provide correct information !", vbOKOnly, _
            "Invalid Entry!"
        Me.txtLoginID.SetFocus
    End If


 'If all information provided are correct then proceed to reset the password and open a frmResetPassword.

DoCmd.OpenForm.frmResetPassword

    
Error Handler:
End Sub

Private Sub txtPrevillage_AfterUpdate()
Me.txtQuestion1.Visible = True
    Me.txtQuestion2.Visible = True
    Me.txtQuestion3.Visible = True
    Me.txtAnswer1.Visible = True
    Me.txtAnswer2.Visible = True
    Me.txtAnswer3.Visible = True
    Me.BtnCancel.Visible = True
    Me.BtnResetPassword.Visible = True
End Sub

Your help to complete the all steps mentioned by me is much appreciated.
 
Last edited:
Your process logic is not right.

After first testing that an entry has been made in the text box, you then go on to check if that entry is in the lookup table. So if nothing is entered, you display a message and then go on to the lookup a missing entry to see if it is in the user table.

Rather than me just giving you the code, can you put a break point on the first If statement line, and press the F9 key. Then click BtnResetPassword and step through your code using the F8 key.

If you do this and still need help, come back again.
 
Ok since you don't want to help for code.

Let's do it button by button event, now i will start with btnsubmitLoginID here all is working except the verification of LoginID.

UserID in tblUsers is autonumber i don't know if that is causing the problem?


Option Compare Database

Private Sub BtnSubmitLoginID_Click()
On Error GoTo errhandlers:

'Check to see if data is entered into the txtLoginID text box.

If IsNull(Me.txtLoginID) Or txtLoginID = "" Then
MsgBox "You must enter a User Name !", vbOKOnly, "Required Data"
Me.txtEmpID.Visible = False
Me.txtPassword.Visible = False
Me.txtPrevillage.Visible = False
Me.txtQuestion1.Visible = False
Me.txtQuestion2.Visible = False
Me.txtQuestion3.Visible = False
Me.txtAnswer1.Visible = False
Me.txtAnswer2.Visible = False
Me.txtAnswer3.Visible = False
Me.BtnCancel.Visible = False
Me.BtnResetPassword.Visible = False
Exit Sub
End If

'Check to see if data entered in txtLoginID is matching with tblUsers or not (Case Sensitive).

If Me.txtLoginID.Value = DLookup("LoginID", "tblUsers", _
"[UserID]=" & Me.txtLoginID.Value) Then

UserID = Me.txtLoginID.Value
DoCmd.Close acForm, "frmuserpasswordRe-set", acSaveNo
Me.txtEmpID.Visible = True
Me.txtPrevillage.Visible = True
Me.txtPassword.Visible = True

Else
MsgBox "Invalid Login ID. Please provide correct information !", vbOKOnly, _
"Invalid Entry!"
Me.txtLoginID.SetFocus

Exit Sub
End If
exit_errhandlers:
Exit Sub
errhandlers:
MsgBox Err.Description, vbCritical
Err.Clear
End Sub


Any correction here will be appreciated.

Thanks

MBA
 
I don't mind helping - that's why me and others freely give of their time. I develop Access applications for a living so why should I just give full solutions where you learn minimal at least. I don't mind helping you solve your problem with you learning along the way. I learned slowly off others, still do.

So now you understand why you should have put the Exit Sub statement in the first if clause.

A tip first off, add Option Explicit as a statement at the top of your code module. This forces you to declare variables and can help avoid typo errors with variables. You can have Access add this automatically to your modules on creation by going to Tools | Options and checking the box Declare Variables.

You don't say what the current issue is. I could guess that the UserId that the user is required to enter is not numeric, in which case you need to have quotes around the lookup variable, ie

DLookup("LoginID", "tblUsers", "[UserID]= '" & Me.txtLoginID.Value & "'")

Now if the docmd.close acform.... is closing the current form, what is the point of setting the text boxes to be not visible after closing the form?
eg Me.txtEmpID.Visible = True
 
Thnkx for your helping hands.

My error is "Data Mismatch in criteria of expression"

Below is modified code after your suggestion.

Option Compare Database
Option Explicit
Dim Userid As Integer
Dim LoginID As String


Private Sub BtnSubmitLoginID_Click()
On Error GoTo errhandlers:

'Check to see if data is entered into the txtLoginID text box.

If IsNull(Me.txtLoginID) Or txtLoginID = "" Then
MsgBox "You must enter a User Name !", vbOKOnly, "Required Data"
Me.txtEmpID.Visible = False
Me.txtPassword.Visible = False
Me.txtPrevillage.Visible = False
Me.txtQuestion1.Visible = False
Me.txtQuestion2.Visible = False
Me.txtQuestion3.Visible = False
Me.txtAnswer1.Visible = False
Me.txtAnswer2.Visible = False
Me.txtAnswer3.Visible = False
Me.BtnCancel.Visible = False
Me.BtnResetPassword.Visible = False
Else

'Check to see if data entered in txtLoginID is matching with tblUsers or not (Case Sensitive).
If Me.txtLoginID.Value = DLookup("LoginID", "tblUsers", "[UserID]= '" & Me.txtLoginID.Value & "'") Then

Userid = Me.txtLoginID.Value
DoCmd.Close acForm, "frmuserpasswordRe-set", acSaveNo

Else
MsgBox "Invalid Login ID. Please provide correct information !", vbOKOnly, _
"Invalid Entry!"
Me.txtLoginID.SetFocus

Exit Sub
End If
End If
exit_errhandlers:
Exit Sub
errhandlers:
MsgBox Err.Description, vbCritical
Err.Clear
End Sub
 
In post #2 I suggested that if you use the full control reference you wouldn't have to concatenate in the control variable and thus avoiding a crap load of problems. Type mismatch is one of them. If you set up your criteria in the DLookUp like:

Code:
DLookup("LoginID", "tblUsers", "[UserID]= Forms![COLOR="Blue"]TheNameOfTheForm[/COLOR]!txtLoginID")
where you would replace TheNameOfTheForm with the actual name of your form, then it doesn't make any difference what type UserID is. It can be text, numeric or even a date.
 
Many Thks somehow its working, but now even i input correct loginID its still giving a message "Invalid Login ID. Please provide correct information !" which i define for wrong Login input.
 
On closer inspection this line

Code:
If [COLOR="Green"]Me.txtLoginID.Value[/COLOR] = DLookup("LoginID", "tblUsers", "[UserID]= '" &[COLOR="green"] Me.txtLoginID.Value[/COLOR] & "'") Then

however you have it now doesn't seem to make sense to me. The part that doesn't make sense is Me.txtLoginID.Value being repeated in the expression. Normally this would be something like:

Code:
If Me.[COLOR="Blue"]txtPassword[/COLOR] = DLookup("LoginID", "tblUsers", "[UserID]= '" & Me.txtLoginID.Value & "'") Then

where txtPassword would be another textbox where the user would enter the password associated with the login id.
 
I have tried it doing many ways including your one also not working to verify the Login ID is correct or not.

txtPassword is in another button which is btnresetPassword their will be many fields going to verify under this button, but in the first step we need to accomplish the btnSubmitLoginID then i can move forward to another button.

I am so irritated with this code why it is not working :banghead:


Code:
Option Compare Database
Option Explicit
Dim UserID As Integer
Dim LoginID As String

Private Sub BtnSubmitLoginID_Click()
On Error GoTo errhandlers:

'Check to see if data is entered into the txtLoginID text box.

If IsNull(Me.txtLoginID) Or txtLoginID = "" Then
    MsgBox "You must enter a User Name !", vbOKOnly, "Required Data"
    Me.txtEmpID.Visible = False
    Me.txtPassword.Visible = False
    Me.txtPrevillage.Visible = False
    Me.txtQuestion1.Visible = False
    Me.txtQuestion2.Visible = False
    Me.txtQuestion3.Visible = False
    Me.txtAnswer1.Visible = False
    Me.txtAnswer2.Visible = False
    Me.txtAnswer3.Visible = False
    Me.BtnCancel.Visible = False
    Me.BtnResetPassword.Visible = False
Else
Me.txtEmpID.Visible = True
Me.txtPassword.Visible = True
Me.txtPrevillage.Visible = True

'Check to see if data entered in txtLoginID is matching with tblUsers or not (Case Sensitive).
If Me.txtLoginID = DLookup("LoginID", "tblUsers", "[UserID]= '" & Me.txtLoginID.Value & "'") Then

        UserID = Me.txtLoginID.Value
        DoCmd.Close acForm, "frmUserpasswordReset", acSaveNo
                
    Else
      MsgBox "Invalid Login ID. Please provide correct information !", vbOKOnly, _
            "Invalid Entry!"
            Me.txtLoginID.SetFocus
    
Exit Sub
End If
End If
exit_errhandlers:
Exit Sub
errhandlers:
    MsgBox Err.Description, vbCritical
    Err.Clear
    End Sub


Please help here i have tried almost everything but dont know what is wrong in it always either given message of "Data type mismatch in criteria of expression" or just given the message that incorrect login even i input correct loginID so irritating :banghead:
 
Stop using a scatter gun approach and look at your logic

First of all
If IsNull(Me.txtLoginID) Or txtLoginID = "" Then

So much for consistency
If IsNull(Me.txtLoginID) Or Me.txtLoginID = "" Then

But even simpler
If len(me.txtLoginID & "") <1 then

But that is not the basic issue. So let's say jsmith is entered in Me.txtLoginID and that is a valid log in.
Then
DLookup("LoginID", "tblUsers", "[UserID]= '" & Me.txtLoginID.Value & "'")

looks at all records for a matching value in the table with that UserID and will return the value of the field LoginID in that record. Is that the same as as the value in LoginID (which I would assume is an numeric index number and clearly not a text string) and I doubt you have the value jsmith in both fields.

When something is not working, add a break point, step through the code and examine the values of variables. Don't look at the code seeing that it should work, but find where it is NOT working.

Don't let the frustration get in the way of logic and problem solving.

Please take all this as advice, not pontification.
 
I have uploaded here partial version of my database, with necessary forms involving in login process.

Just to give you the idea where i am going wrong.

remember btnSubmitLoginID is just limited to loginID process nothing to do with password and other fields of verification.

Password and other fields will appear once loginID will be verified at top and i will code it in btnResetPassword at bottom of form which is now deleted by me.

at the last but not the least i never mind sensible and productive words from anyone.
 

Attachments

There is no table or query Security_table in your database so there is an immediate run time error when the OK button is clicked.

Nor is there any form named Login_Form
DoCmd.Close acForm, "Login_Form"

Nor is the password stored in a field called Password, its strPassword in your tblUsers
"Password='" & Me.Passwordtxt.Value & " '")
 
I just realized my previous post was not referring to the form you were asking about.

If you re-read my post #15, I was suggesting that the UserID was probably a numeric table therefore
DLookup("LoginID", "tblUsers", "[UserID]= '" & Me.txtLoginID.Value & "'")

is going to give a run time error
 

Users who are viewing this thread

Back
Top Bottom