User Reset Password .vba

mba_110

Registered User.
Local time
Today, 10:54
Joined
Jan 20, 2015
Messages
280
Please need help with below code it returned "Data type mismatch error" and "Data type mismatch criteria expression error"

Many thanks in advance for your help.

Code:
Option Compare Database
Option Explicit

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 entered Login ID is listed in tblUsers or not
    Me.txtLoginID.Value = DLookup("LoginID", "tblUsers", "userId='" & Me.txtLoginID & "'")
    MsgBox "Entered Login details are not matching with registered user, please provide correct login ID !", vbOKonly, "Login Verification"
    Me.txtEmpID.Visible = True
    Me.txtPassword.Visible = True
    Me.txtPrevillage.Visible = True
Exit Sub
End If
exit_errhandlers:
Exit Sub
errhandlers:
    MsgBox Err.Description, vbCritical
    Err.Clear
    End Sub

This form to verify the users login id ONLY with tblusers information.
 
Given the error, my guess would be that userId is not defined as Text, which is what the syntax

"userId='" & Me.txtLoginID & "'"

would be correct for, but defined as a Number, which would require

"userId=" & Me.txtLoginID

You also appear to be popping up your messagebox without actually checking the returned LoginID.

Linq ;0)>
 
Sorry I forgot to mention

UserID is number and not text in tblUsers.

I am sorry but its still same error, i change the following do i need to change also something?

Me.txtLoginID.Value = DLookup("LoginID", "tblUsers", "userId=" & Me.txtLoginID & "'")

Can you please mention where i have to input the ;0)>
 
Last edited:
It nneeds to be

Me.txtLoginID.Value = DLookup("LoginID", "tblUsers", "userId=" & Me.txtLoginID)
 
here is the full code


Code:
Option Compare Database
Option Explicit

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", vbInformation, "Login Verification"
    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 entered Login ID is listed in tblUsers or not
    Me.txtLoginID.Value = DLookup("LoginID", "tblUsers", "userId=" & Me.txtLoginID)
    MsgBox "Entered Login details are not matching with registered user, please provide correct login ID !", vbInformation, "Login Verification"
    Me.txtEmpID.Visible = True
    Me.txtPassword.Visible = True
    Me.txtPrevillage.Visible = True
Exit Sub
End If
exit_errhandlers:
Exit Sub
errhandlers:
    MsgBox Err.Description, vbCritical
    Err.Clear
    End Sub
 
As I and others have said you aren't comparing your values correctly.
Please tell us what you think you are achieving with this line of code?

Me.txtLoginID.Value = DLookup("LoginID", "tblUsers", "userId=" & Me.txtLoginID)

Bear in mind before answering the question that Me.txtLoginID.Value is the exact syntax equivalent of Me.txtLoginID
 
This is to check the txtloginID entered is correct or not as per the record of tblUsers field [LoginID]

I don't know if its make any sense in the code :confused: but i am pretty new to the coding so, please ignore in wrong methods and guide/provide the correct one.


Remember i am checking only LoginID details not password or anything else these all will come in another button which i need to code once this get done properly.
 
So just so we are completely clear - what you want to do is check if the text entered in Me.txtLoginID matches the field LoginID for that user.
The problem / failure in logic is how are you going to look that up if they provide the wrong txtLoginID ?

At the moment let's put values into your code, we'll make txtLoginID = 88 .

Code:
88 = DLookup("LoginID", "tblUsers", "userId= 88"
Do you now see why your code makes no sense. I suspect you should be asking a user for their UserName And their LoginID number then check if both those items match.

Something like
Code:
  If Me.txtUserName <> DLookup("UserName", "tblUsers", "[userId]=" & Me.txtLoginID) Then
    MsgBox "Entered Login details are not matching with registered user, please provide correct login ID !", vbInformation, "Login Verification"
 
As I mentioned I need to verify the LoginID nothing else at the moment because this form has to work for reset users details who forgot their password in order to verify their password (recreate) and other security details i need to filter their steps [loginID] which is txtLoginID on the form once its verified the remaining fields will appear constantly.


I have nothing to do with Username because this field doesn't have any role in here, only the unique ID is UserID (its a number field) in tblusers which is (PK) of tblUser.


Again I need to verify only LoginID which is entered by user on form nothing else right now.
 
All you are doing is checking that an LoginID exists in that case. So a simple

If DCount("LoginID", "tblUsers", "userId=" & Me.txtLoginID) > 0 Then ' It's a valid number.
 
I am attaching here the strip version of DB, please see as the error is still their.

Dlookup for other tables are not available as i am uploading the strip version so we need to examine only the txtLoginID.
 

Attachments

Okay - where to start - you are confusing everyone here with your field names and the associated / assumed terminology.
Your LoginID in your Users table is text and is (confusingly) either their name or surname.

If you have two users whose LoginID is "Fred" then doing a DLookup will only return the first one it comes to.

You (also confusingly) have two tables Employees and Users. The Users ones appears to only hold security question information for the employee.

I would not have these separate tables. I probably wouldn't bother with the security questions in this format. Store a password reset email address, and require the user to enter that email address (which would be unique - all legal email addresses are by definition) and maybe their surname as a double check. If both match then simply reset their password to a random one and email it to them at the reset email address.

Set a Flag on the employees record that they have a temporary password, and when they log in to your system, send them to a form that already has their details on it and only allows them to change their password and log them in.

If this sounds a bit involved it is, but it does allow you to also create alternative password recovery options if you ever go the Web App route.
 
My apologies,

I will go back and normalize/redesign database and make sure it's satisfy the requirement of project and maintain the correct relationships without duplicates.

let me start from scratch, once done with tables will post in a new thread,

Thanks for everyone here, for your precious time.

MA
 

Users who are viewing this thread

Back
Top Bottom