Validation rule

morlan

Registered User.
Local time
Today, 22:38
Joined
Apr 23, 2003
Messages
143
Hi,

I need to apply the following validation rule to a form text box.

The user can enter either the letter H, W, M or E or any combination of the 4. The user should not be able to enter any other charecters or multiples of the same letter.. ie. HH.
Also, the user should not be able to enter more than 4 of the letters

Cheers!
 
Morlan,

I'm not sure what would be less fun, typing in a validation rule similar to this (not complete -- think you're looking at about 24 in all) or trying to do this in code...

Like "HWME" Or "HWEM" Or "HMWE" Or "HMEW" Or "HEWM", etc.

Regards,
Tim
 
Try this idea to get around it - I used toggle buttons.
 

Attachments

Mile-O-Phile said:
Try this idea to get around it - I used toggle buttons.

That works great ! I need to use that code for the other two fields. Do I just paste that code in 2 more times?

example

Private Sub tglE1_Click()
Call CorrectCodes(Me.tglE1)
End Sub

Private Sub tglH1_Click()
Call CorrectCodes(Me.tglH1)
End Sub

Private Sub tglM1_Click()
Call CorrectCodes(Me.tglM1)
End Sub

Private Sub tglW1_Click()
Call CorrectCodes(Me.tglW1)
End Sub

Sub CorrectCodes(ByVal tglCode As ToggleButton)
If tglCode = True Then
Me.txtResult1 = Me.txtResult1 & tglCode.Caption
Else
Dim intCounter As Integer
For intCounter = 1 To Len(Me.txtResult1)
If Mid(Me.txtResult1, intCounter, 1) = tglCode.Caption Then
Me.txtResult1 = Left(Me.txtResult1, intCounter - 1) & Mid(Me.txtResult1, intCounter + 1)
Exit For
End If
Next intCounter
End If
End Sub

Private Sub tglE2_Click()
Call CorrectCodes(Me.tglE2)
End Sub

Private Sub tglH2_Click()
Call CorrectCodes(Me.tglH2)
End Sub

Private Sub tglM2_Click()
Call CorrectCodes(Me.tglM2)
End Sub

Private Sub tglW2_Click()
Call CorrectCodes(Me.tglW2)
End Sub

Sub CorrectCodes(ByVal tglCode As ToggleButton)
If tglCode = True Then
Me.txtResult2 = Me.txtResult2 & tglCode.Caption
Else
Dim intCounter As Integer
For intCounter = 1 To Len(Me.txtResult2)
If Mid(Me.txtResult2, intCounter, 1) = tglCode.Caption Then
Me.txtResult2 = Left(Me.txtResult2, intCounter - 1) & Mid(Me.txtResult2, intCounter + 1)
Exit For
End If
Next intCounter
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom