2 String values equal each other - Case Sensitive

  • Thread starter Thread starter Tony_VBACoder
  • Start date Start date
T

Tony_VBACoder

In Access 2002 (SP2) with WinXP, I have 2 strings that I
am comparing when a user enters their password into a
LogIn form. The variables and their values are below:

' This is the password stored in the User's table
sPassword = "robert"
' This is the password the entered in the password text
box on the LogIn Form
sPasswordEntered = "ROBert"

When the following code is executed, I get a True result,
when in fact I should get a FALSE result:

If sPassword = sPasswordEntered Then
bSuccess = TRUE
Else
bSuccess = FALSE
End If

What is the best method to ensure that the user has
entered the correct password (case sensitivity does matter
here)?
 
Sorry that should be Option Compare Binary, Option Compare Text will produce
the result you are current experiencing.
 
Roger Carlson said:
Try the ASC function:

If Asc(sPassword) = Asc(sPasswordEntered) Then ...

Asc() only evaluates the first character in a string though.
 
Tony_VBACoder said:
In Access 2002 (SP2) with WinXP, I have 2 strings that I
am comparing when a user enters their password into a
LogIn form. The variables and their values are below:

' This is the password stored in the User's table
sPassword = "robert"
' This is the password the entered in the password text
box on the LogIn Form
sPasswordEntered = "ROBert"

When the following code is executed, I get a True result,
when in fact I should get a FALSE result:

If sPassword = sPasswordEntered Then
bSuccess = TRUE
Else
bSuccess = FALSE
End If

What is the best method to ensure that the user has
entered the correct password (case sensitivity does matter
here)?


I like this way:

If StrComp(sPassword, sPasswordEntered, _
vbBinaryCompare) = 0 Then
bSuccess = TRUE
 
Thanks.

StrComp worked the Best.

-----Original Message-----



I like this way:

If StrComp(sPassword, sPasswordEntered, _
vbBinaryCompare) = 0 Then
bSuccess = TRUE
 
Back
Top