validation rule not easy

teel73

Registered User.
Local time
Today, 08:28
Joined
Jun 26, 2007
Messages
205
I'm trying to set up a validation rule for a control on my form. The control is called [evDate] which captures the date entered. If the date is later than the current date I want a simple msgbox to popup as the validation text and the user can't go beyond that field without entering a valid date. But my problem is that I need a second condition that results to a yes/no answer. If the date entered is earlier than the current date then I want a msgbox with a yes/no answer. Here's what I have on the afterUpdate event of the [evDate] control.

Code:
    If [evDate] > Date Then
        MsgBox "can't be later than today."
        DoEvents
        evDate.SetFocus
    
    ElseIf [evDate] < Date Then
        results = MsgBox("you entered a date earlier than today. do you want to continue with the entry",vbYesNo)
        If results = vbYes then
        Else
        DoEvents
        evDate.SetFocus
        Endif

    End If

This code gives me the right messages but it allows the user to continue with not putting in a date that meets the requirements. Can someone help me with this?
 
Do the validation in the BeforeUpdate() handler. Then you can cancel the event if the validation fails, and the user is forced to keep trying.
Code:
Private Sub Text1_BeforeUpdate(Cancel As Integer)
   If FailsValidation Then
      Cancel = True
      Me.Text1.Undo
   End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom