In case you (or anyone else) are interested, I've finished the code that tests ALL the following conditions:
AT LEAST 8 characters including:
1. At least two letters - BOTH upper and lower case required
2. At least one number
3. At least one special character from this list: ! @ $ % # & * (modify as required)
Place this function in a standard module
Code:
Public Function ValidatePwd(varPassword As Variant) As Boolean
Dim blnValid As Boolean
Dim blnValidCriteria As Boolean
Dim intChar As Integer
blnValid = False
blnValid = Len(varPassword) >= 8
If blnValid Then
blnValidCriteria = False
For intChar = 1 To Len(varPassword)
If InStr(1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", Mid(varPassword, intChar, 1), vbBinaryCompare) > 0 Then
blnValidCriteria = True
Exit For
End If
Next
blnValid = blnValidCriteria
Else
GoTo EndRoutine
End If
If blnValid Then
blnValidCriteria = False
For intChar = 1 To Len(varPassword)
If InStr(1, "abcdefghijklmnopqrstuvwxyz", Mid(varPassword, intChar, 1), vbBinaryCompare) > 0 Then
blnValidCriteria = True
Exit For
End If
Next
blnValid = blnValidCriteria
Else
GoTo EndRoutine
End If
If blnValid Then
blnValidCriteria = False
For intChar = 1 To Len(varPassword)
If InStr(1, "0123456789", Mid(varPassword, intChar, 1), vbBinaryCompare) > 0 Then
blnValidCriteria = True
Exit For
End If
Next
blnValid = blnValidCriteria
Else
GoTo EndRoutine
End If
If blnValid Then
blnValidCriteria = False
For intChar = 1 To Len(varPassword)
If InStr(1, "!@$%#&", Mid(varPassword, intChar, 1), vbBinaryCompare) > 0 Then
blnValidCriteria = True
Exit For
End If
Next
blnValid = blnValidCriteria
Else
GoTo EndRoutine
End If
ValidatePwd = blnValid
EndRoutine:
'Debug.Print blnValid
If blnValid = True Then
MsgBox "This is a valid password"
Else
MsgBox "You must enter AT LEAST 8 characters including:" & vbCrLf & _
"1. At least two letters - both upper and lower case required" & vbCrLf & _
"2. At least one number" & vbCrLf & _
"3. At least one special character ! @ $ % # & *"
End If
End Function
In your form, place this code in the Before_Update event of your textbox e.g. Text4
Code:
Private Sub Text4_BeforeUpdate(Cancel As Integer)
ValidatePwd Text4
End Sub
The advantage of this method is it can be called from anywhere - no validation code needed
HTH