2 String values equal each other - Case Sensitive

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)?
 
S

solex

Sorry that should be Option Compare Binary, Option Compare Text will produce
the result you are current experiencing.
 
R

Rick Brandt

Roger Carlson said:
Try the ASC function:

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

Asc() only evaluates the first character in a string though.
 
M

Marshall Barton

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
 
T

Tony_VBACoder

Thanks.

StrComp worked the Best.

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



I like this way:

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top