Okay. Here are two functions that will accomplish what you want. The
comments in the code explain how the functions work.
First you pass the password to PickTwo which will return the two numbers
based on the length of the password.
Then you pass the password, the string with the two number returned from
PickTwo, and the two characters supplied by the customer to VerifyTwo. If
the characters supplied by the customer match the characters in the password,
True is returned. If they do not, False is returned.
The comparison is case sensitive, so "x" does not = "X"
I would suggest you start with a command button to get the two numbers:
Private Sub cmdGetNumbers_Click()
Me.txtTwoNumbers = PickTwo(DLookup("[PWd]", "tblCustomer", _
"[CustID] = " & Me.txtCustID))
End Sub
Then when the agent gives the numbers to the customer and the customer
responds with the characters, the agent will type the two characters into a
text box. Use the After Update event of the text box to verify the
characters:
Private Sub txtCheckChars_AfterUpdate()
If Not VerifyTwo(DLookup("[PWd]", "tblCustomer", _
"[CustID] = " & Me.txtCustID), Me.txtTwoNumbers, Me.txtCheckChars)
Then
MsgBox "Password Not Valid"
Me.txtTwoNumbers = Null
Me.txtCheckChars = Null
Me.cmdGetNumbers.SetFocus
End Sub
'---------------------------------------------------------------------------------------
' Procedure : PickTwo
' DateTime : 6/4/2008 09:13
' Author : Dave Hargis
' Purpose : Generate two random numbers in ascending order
' : Minimum number will be 1, Maximum number will be the length of
the
' : String passed
' Returns : A string with the two generated numbers separated by a comma
and a space
' Example : Numbers generated are 8 and 3
' : The return will be "3, 8" (the qoutes are not returned)
' : The Do Loop ensures duplicated numbers will no be returned
'---------------------------------------------------------------------------------------
'
Public Function PickTwo(strPassword As String) As String
Dim lngFirstNumber As Long
Dim lngSecondNumber As Long
Dim lngCheckNumber As Long
Randomize
Do Until lngFirstNumber <> lngSecondNumber
lngFirstNumber = Int((Len(strPassword) * Rnd) + 1)
lngCheckNumber = Int((Len(strPassword) * Rnd) + 1)
If lngCheckNumber < lngFirstNumber Then
lngSecondNumber = lngFirstNumber
lngFirstNumber = lngCheckNumber
Else
lngSecondNumber = lngCheckNumber
End If
Loop
PickTwo = CStr(lngFirstNumber) & ", " & _
CStr(lngSecondNumber)
End Function
'---------------------------------------------------------------------------------------
' Procedure : VerifyTwo
' DateTime : 6/4/2008 09:27
' Author : Dave Hargis
' Purpose : Checks to see if the two character positions selected in the
password
' : match the characters actually in the password
' : The check is case sensitive
' Arguments : strPassword - The password to verify
' : strPositions - The two positions to compare - a string of two
numbers
' : in ascending order separated by a comma and a space
' : strChars - The two characters that should be in the positions in
' : strPassword defined by the two numbers in strPositions
'---------------------------------------------------------------------------------------
'
Public Function VerifyTwo(strPassword As String, _
strPositions As String, strChars As String) As Boolean
Dim varCheck As Variant
Dim lngFirstChar As Long
Dim lngSecondChar As Long
varCheck = Split(strPositions, ",")
VerifyTwo = (Asc(Left(strChars, 1)) = Asc(Mid(strPassword, varCheck(0),
1)) And _
Asc(Right(strChars, 1)) = Asc(Mid(strPassword, varCheck(1), 1)))
End Function