Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Access Cancel update of Date field if not valid on bound form

Hi. I want to use the following code to check whether a date entered is valid.How do I cancel the update of the field if the date entered is not valid?

Private Sub DateofBirth_AfterUpdate()
    'Test if applicant is under required age.....
    Dim CurrentAge As Integer
   
    If oCountry = "Samoa" Then
        oModalAge = 18
    ElseIf oCountry = "Tonga" Then
        oModalAge = 21
    ElseIf oCountry = "Liberia" Then
        oModalAge = 18
    ElseIf oCountry = "Fiji" Then
        oModalAge = 21
    Else
        oModalAge = 18
    End If
   
    ''CurrentAge = AgeYears(#12/31/1985#)
    CurrentAge = AgeYears(Me.DateOfBirth)
    If CurrentAge < oModalAge Then
        MsgBox "Applicant must be at least " & CStr(oModalAge) & " years old!", , "CAVR - ATD": Exit Function
    End If
End Sub
ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

Thanks