Avatar of Murray Brown
Murray Brown
Flag 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
Microsoft Access

Avatar of undefined
Last Comment
Murray Brown

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
John Tsioumpris

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Partha Mandayam

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Murray Brown

ASKER
Thanks
Your help has saved me hundreds of hours of internet surfing.
fblack61