Validate password case sensitive

puuts

New member
Local time
Today, 05:57
Joined
Jan 20, 2014
Messages
8
Hello Gurus,

I'm new to access vba and I'm trying to create a login form. I have already my code to login but i want to validate the password in 'case sensitive' basis. Below is only what I've got so far.

Thanks in advance!

Code:
Private Sub cmdLogin_Click()  Dim login_validation As Variant  login_validation = DLookup("Password", "tblLogin", "Username='" & Nz(txtUsername.Value, "") & "'") If Nz(login_validation, "") <> Nz([txtPassword].Value, "") Then      MsgBox "Incorrect Password. Please try again."     txtUsername.Value = ""     txtPassword.Value = ""     txtUsername.SetFocus Else   MsgBox "Hi " & txtUsername.Value & "," & vbNewLine & vbNewLine & "you have successfully login!"   DoCmd.OpenForm "frmMain"    End If    End Sub
 
Your CODE needs formatting, but without looking at the code I would say use StrComp method with vbBinaryCompare as the argument.
Code:
? StrComp("Hello", "hello", vbBinaryCompare)
-1 
? StrComp("Hello", "Hello", vbBinaryCompare)
 0 
? StrComp("hello", "Hello", vbBinaryCompare)
 1
 
Code:
Private Sub cmdLogin_Click()  Dim login_validation As Variant  login_validation = DLookup("Password", "tblLogin", "Username='" & Nz(txtUsername.Value, "") & "'") If Nz(login_validation, "") <> Nz([txtPassword].Value, "") Then      MsgBox "Incorrect Password. Please try again."     txtUsername.Value = ""     txtPassword.Value = ""     txtUsername.SetFocus Else   MsgBox "Hi " & txtUsername.Value & "," & vbNewLine & vbNewLine & "you have successfully login!"   DoCmd.OpenForm "frmMain"    End If    End Sub

I was bored so I made this easier to read:
Code:
Private Sub cmdLogin_Click()  
Dim login_validation As Variant  
login_validation = DLookup("Password", "tblLogin", "Username='" & Nz(txtUsername.Value, "") & "'") 
If Nz(login_validation, "") <> Nz([txtPassword].Value, "") Then      
     MsgBox "Incorrect Password. Please try again."    
     txtUsername.Value = ""     
     txtPassword.Value = ""     
     txtUsername.SetFocus 
Else   
     MsgBox "Hi " & txtUsername.Value & "," & vbNewLine & vbNewLine & "you have successfully login!"       
     DoCmd.OpenForm "frmMain"    
End If    
End Sub
 
Hi Foe,

Thanks for the correcting. Could you please help me with the 'case sensitive' problem?
 

Users who are viewing this thread

Back
Top Bottom