Login Form Data Mismatch

mba_110

Registered User.
Local time
Yesterday, 17:39
Joined
Jan 20, 2015
Messages
280
Dear All,

I am doing a login form for my database using online references and videos.

Below is the code for my login form.

Code:
Private Sub Form_Load()
Dim Security As Integer

Me.txtUser = Environ("USERNAME")

If IsNull(DLookup("UserSecurity", "Userslist_table", "[UserLogin]='" & Me.txtUser & "'")) Then
MsgBox "No Usersecurity set up for this user. please contact the Admin", vbOKOnly, "Login info"
Me.NavigationButton11.Enabled = False
Else
Security = DLookup("UserSecurity", "Userslist_table", "[Userlogin]='" & Me.txtUser & "'")
If Security = 1 Then
Me.NavigationButton11.Enabled = True

Else
Me.NavigationButton11.Enabled = False
End If

End If

End Sub
Code:

i am facing problem for run-time error type mismatch '13': i have listed below field names which is used in above coding.

UserSecurity_table
[SecurityID] is Autonumber field
[SecurityLevel] is Text field

Userlist_table
[UserID] is autonumber field
[Username] is text field
[Userlogin] is text field
[Usersecurity] is text field
[Password] is text field

Can you please help to sort this out.

regards,

MBA
 
My first thought would be the way you are checking SecurityLevel, either change the table to a number or make what you are checking a string.


Try that first.
 
I did try on both string & integer coming with same issue.

What field or data need to be change please do let me know or any coding please provide.

Sorry to bother you i am doing a small project and don't know much about coding.

regards,

MBA
 
Your setting Security as an integer then assigning it a text value.


Change you field to a numeric field in the database and try that.
 
Sorry again which field you want me to change to numeric?
 
Assuming the Usersecurity field in table userlist_table is a reference to the security level in UserSecurity_Table then chage UserSecurity in userlist_table to an integer value as it is a FK to the other table.

Then you can change you code slightly, as unless you need Security for something else later on, then you can just check the result of the dlookup:

Code:
Private Sub Form_Load()

Me.txtUser = Environ("USERNAME")

If IsNull(DLookup("UserSecurity", "Userslist_table", "[UserLogin]='" & Me.txtUser & "'")) Then
     MsgBox "No Usersecurity set up for this user. please contact the Admin", vbOKOnly, "Login info"
     Me.NavigationButton11.Enabled = False
ElseIf DLookup("UserSecurity", "Userslist_table", "[Userlogin]='" & Me.txtUser & "'") = 1 Then
     Me.NavigationButton11.Enabled = True
Else
     Me.NavigationButton11.Enabled = False
End If

End Sub
 
I cant change the UserSecurity in userlist_table to an integer value because its mentioned the user privilege whether its admin or user.

Below is command [OK] button code on dialogue form for login.

Private Sub Command1_Click()
If IsNull(Me.txtLoginID) Then
MsgBox "Please enter Login ID", vbInformation, "Login ID Required"
Me.txtLoginID.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please enter password", vbInformation, "Password Required"
Me.txtPassword.SetFocus
Else
'Process the job
If (IsNull(DLookup("userLogin", "UsersList_table", "UserLogin='" & Me.txtLoginID.Value & " ' "))) Or _
(IsNull(DLookup("password", "UsersList_table", "Password='" & Me.txtPassword.Value & " ' "))) Then
MsgBox "incorrect LoginID or Password"
Else
'MsgBox "Login ID and Password Identified"
DoCmd.OpenForm "Navigation_Form"
DoCmd.Close acForm, "Login_Form"
End If
End If
End Sub

The error is coming in below line after debug the error.

Else
Security = DLookup("UserSecurity", "Userslist_table", "[Userlogin]='" & Me.txtUser & "'")
Kindly help me out the issue is still their.

regards,

MBA
 
I think you need to review the process that you are following here, as from what I can see your not checking if the password is correct, only that a password has been entered.

You have a second table which has your security levels in it, the field in e user table should reference this access level in your other table, and therefore should have a numeric value.
 
Dears Please find below the code again as per your described method.

[OK] button Code on click event on Login Form


Code:
Private Sub Command1_Click()
If IsNull(Me.txtLoginID) Then
    MsgBox "Please enter Login ID", vbInformation, "Login ID Required"
    Me.txtLoginID.SetFocus
ElseIf IsNull(Me.txtPassword) Then
    MsgBox "Please enter password", vbInformation, "Password Required"
    Me.txtPassword.SetFocus
Else
    'Process the job
    If (IsNull(DLookup("userLogin", "UsersList_table", "UserLogin='" & Me.txtLoginID.Value & " ' "))) Or _
        (IsNull(DLookup("password", "UsersList_table", "Password='" & Me.txtPassword.Value & " ' "))) Then
        MsgBox "incorrect LoginID or Password"
    Else
        'MsgBox "Login ID and Password Identified"
        DoCmd.OpenForm "Navigation_Form"
        DoCmd.Close acForm, "Login_Form"
    End If
End If
End Sub



Below is the coding where i am having problem.


Code:
Private Sub Form_Load()
Dim Security As Integer

Me.txtUser = Environ("USERNAME")

If IsNull(DLookup("UserSecurity", "Userslist_table", "[UserLogin]='" & Me.txtUser & "'")) Then
    MsgBox "No Usersecurity set up for this user. please contact the Admin", vbOKOnly, "Login info"
    Me.NavigationButton11.Enabled = False
Else
    Security = DLookup("UserSecurity", "Userslist_table", "[Userlogin]='" & Me.txtUser & "'")
    If Security = 1 Then
        Me.NavigationButton11.Enabled = True
        
    Else
        Me.NavigationButton11.Enabled = False
        End If
        
End If

End Sub


Below is the line where my error is showing in debug

Code:
 Security = DLookup("UserSecurity", "Userslist_table", "[Userlogin]='" & Me.txtUser & "'")


Dear Acropolis

The above code is just a beginning and i have lot to add later on like forgot password or change password options etc but [Usersecurity] & [Securitylevel] is indicating the users level of privilege so it cant be changed to numeric this will get confused to user.

I have clearly mentioned the fields properties in my first post, please if you have any other alternative or change in coding kindly provide the code itself.

regards,

MBA
 
Code:
Security = DLookup("[UserSecurity]", "Userslist_table", "[Userlogin]='" & Me.txtUser & "'")


See above, that might work.


If you are storing the user security level in your table as a text field, then what is the point of the UserSecurity_table table that you have mentioned? It would be better to store you security levels in UserSecurity_table and you reference this to Userlist_table using the ID number, this won't get confusing to the user you what you show them in the text field from UserSecurity_table not the number.
 
The Code i have posted you have returned me the same code.

in your paragraph "If you are storing the user security level in your table as a text field, then what is the point of the UserSecurity_table table that you have mentioned? It would be better to store you security levels in UserSecurity_table "

i am sorry but i am confused not the reply i wanted.
 
Code:
    If (IsNull(DLookup("userLogin", "UsersList_table", "UserLogin='" & Me.txtLoginID.Value & " ' "))) Or _
        (IsNull(DLookup("password", "UsersList_table", "Password='" & Me.txtPassword.Value & " ' "))) Then
This is SO wrong

Dim Security As Integer
Security = DLookup("UserSecurity", "Userslist_table", "[Userlogin]='" & Me.txtUser & "'")
From your first post:
Userlist_table
[UserID] is autonumber field
[Username] is text field
[Userlogin] is text field
[Usersecurity] is text field
[Password] is text field

you cant store a Text field into a integer variable.
 

Users who are viewing this thread

Back
Top Bottom