Case Sensitive Variable check

Bilbo_Baggins_Esq

Registered User.
Local time
Today, 13:33
Joined
Jul 5, 2007
Messages
586
I've tried searching around, but either I'm not using the correct words, or it does not exisit, or is burried too deep for me to find it.

Is there a way to force validation of a variable down to the case level of the letters?

Such as what would be used for passwords?

Capture a string value from a table
Compare it against the value of a field in a form

Even if it has the same text but different case for some or all of the letters, a basic comparrison will say they are the same.

I need to force a fully case sensitive match.

Any help?
 
Check this out:

Setting VBA Module Options Properly
http://www.fmsinc.com/free/newtips/vba/Option/index.html#OptionCompare

Sample code of what you are after:

Code:
[B][COLOR=Blue]Option Compare Binary[/COLOR][/B]
Option Explicit

Private Sub btnTest_Click()

  Dim strA As String
  Dim strB As String

  strA = "This is a way cool test!"
  strB = "THIS is a way cool test!"

  If strA = strB Then
    Debug.Print "They Match!"
  Else
    Debug.Print "They Do Not Match!"
  End If

End Sub
Immediate Window output:
Code:
They Do Not Match!
So, since it is a module level setting, perhaps have a special module perform the CaSe SeNsItIvE comparisons, and leave the rest of the modules at the Access default.
 
Here is another method which works and allows you to leave the Option Compare set to Database (default).

Code:
[B]Option Compare Database[/B]
Option Explicit

Private Sub btnTest_Click()

  Dim strA As String
  Dim strB As String

  strA = "This is a way cool test!"
  strB = "THIS is a way cool test!"

  If [B]StrComp(strA, strB, vbBinaryCompare) = 0[/B] Then
    Debug.Print "They Match!"
  Else
    Debug.Print "They Do Not Match!"
  End If

End Sub
Immediate Window output:
Code:
They Do Not Match!
 

Users who are viewing this thread

Back
Top Bottom