Case Sensitive

NigelShaw

Registered User.
Local time
Today, 00:13
Joined
Jan 11, 2008
Messages
1,575
Hi all,

can you make a textbox case sensitive for a login box? so for example, a password is LetMeIn but letmein would not work?

i have the password matching on a DLookup and i am trying to get the passwords to be exact before it allows access to the db



regs,

Nigel
 
I don't think there is a built in function to do this but you should be able to write one.
 
Something like the following:

Code:
Private Sub Command4_Click()
If Not fncCompare(Me.Text0, Me.Text2) Then
    MsgBox "Password error!"
    Exit Sub
End If

MsgBox "Password Correct!"

End Sub
===================================================
Public Function fncCompare(strOne As String, strTwo As String)

Dim intLen As Integer

fncCompare = False

If strOne <> strTwo Then Exit Function

For intLen = 1 To Len(strOne)
    If Asc(Mid(strOne, intLen, 1)) <> Asc(Mid(strTwo, intLen, 1)) Then Exit Function
Next intLen

fncCompare = True

End Function
 
Hi Ken,

thanks for this. i am struggling just a little though. i have placed the fncCompare into a module but cannot seem to integrate the small code section inot my validate line-

If Me.txtPassword.Value = DLookup("Password", "LoginQry") Then
Me.LoggedOn.Value = True

txtPassword is the text box receiving the input password
the dlookup is matching the password in the query
LoggedOn is a tickbox that is made true on the form to proceed

in a sense, i need to match the dlookup with the txtPassword so would i-

Dim GetPassword as String

GetPassword = DLookup("Password", "LoginQry")

If Not fncCompare(Me.txtPassword, GetPassword) Then
MsgBox "Password error!"
Exit Sub
Else
Me.LoggedOn.Value = True
DoCmd.Close acForm, "LoginFrm"

End If



regs,

Nigel
 
Try something like this:

Code:
Private Sub cmdLogin_Click()

   dim strPWDOne as string
   dim strPWDTwo as string

   strPWDOne = Me.txtPassword
   strPWDTwo = DLookup("Password", "LoginQry")

   If Not fncCompare(strPWDOne, strPWDTwo) Then
      MsgBox "Password error!"
      Exit Sub
   End If

   MsgBox "Password Correct!"
   'Other login code goes here

End Sub
 
Hi Ken,

bloomin brilliant. works perfectly. had to change function items to strPWDOne & strPWDTwo.

thank you very very much :):)


nigel
 
Just to mention - the built in function StrComp allows you to make case sensitive comparisons - if you use the vbBinaryCompare option.
The function returns 0 (zero) for a match and 1 or -1 for not (so don't assume a standard True/False return).
(Have a look in Online Help for the exceptions - Null values etc).

e.g.
StrComp("Hello", "Hello", vbBinaryCompare)
0
StrComp("Hello", "hello", vbBinaryCompare)
-1
StrComp("hello", "Hello", vbBinaryCompare)
1

As an aside, in itself - Jet is capable of supporting case sensitive data types.
But these are rarely implemented unless it is specifically what you want to be doing.
Naturally a function like strComp introduced into a large scale query can have substantial performance consequences - and it is then that perhaps the comparison is best done at the engine level.

Cheers!
 
Whoops. Oh well, maybe I'll get an 'e' for effort. :p
 
The OP has a solution which is working well for them regardless of anything else.
Surely that gets what they need - an "h" for Happy. :-)
 
I was wondering how my function would compare with the built-in function in a performance test...
 

Users who are viewing this thread

Back
Top Bottom