how to make validation rule(s)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone point me to a source to help me build a validation process.

I have a form where the user is required to enter a [disposition]. I want
the user to either pick one from the list (simple part), or enter a number &
letter sequence (this is the difficult part) that must be formatted properly.

The sequence has to be like this :

###L# ie: 257A1 or 264B2

The sequence must also be within a range, specifically the first three
numbers must be between 202 to 288.

Would it make more sense to compare the user input to a list of acceptable
entries?

Any help would be appreciated.

Cheers
 
Use the before update event of the control on the form.

So, your code could look like:

dim testnum as integer

If IsNull(Me!Dispostion) = True Then
Exit Sub
End If

If (Me!Dispostion Like "###[A-Z]#") = False Then
Cancel = True
MsgBox "Format of data must be Number,Number,Number, Letter, Number",
_
vbExclamation, "wrong format"

Exit Sub

End If

' if we get here..then format is correct..check range...

testnum = Left(Me!Dispostion, 3)

If (testnum < 202) Or (testnum > 288) Then
Cancel = True
MsgBox "allowable range for number is 202 to 288", _
vbExclamation, "bad number range"
Exit Sub

End If

Note that the "requirement" for this field should be set in the forms before
update event..and not the above control before update event. (thus, not how
I just exit and ignore all the code if the field is empty (not entered).
 
Thanks Albert....wasn't expecting the whole solution, but appreciated just
the same. Your solution has answered some other issues for me and given me
new ideas.

Cheers
 
Back
Top