AfterUpdate

7anthala

Registered User.
Local time
Tomorrow, 00:23
Joined
Apr 7, 2014
Messages
41
i want to use the AfterUpdate to calculate the age using two textfieds

Private Sub Birthdate_AfterUpdate()
Me.AGE = DateDiff("yyyy", [Birthdate], Now()) + Int(Format(Now(), "mmdd") < Format([Birthdate], "mmdd"))
End Sub

but it wont work
 
Try this:

Code:
Private Sub Birthdate_AfterUpdate()
 
Dim AgeVal As Long
 
    AgeVal = DateDiff("yyyy", BDate, Date)
    If Date < DateSerial(DatePart("yyyy", Date), DatePart("m", Me.Birthdate), DatePart("d", Me.Birthdate)) Then AgeVal = AgeVal - 1
    Me.AGE = AgeVal
 
End Sub
 
Last edited:
I am not an Access expert, but since when could you put a comparison in an assignment statement ( Int(Format(Now(), "mmdd") < Format([Birthdate], "mmdd")))
 
i didnt work. if anybody knows what is the best way to automatic calculate the age in a form
 
i tried this and it worked the way i needed
code:
Private Sub Birthdate_AfterUpdate()
Me.AGE.Value = DateDiff("yyyy", [Birthdate], Now()) + Int(Format(Now(), "mmdd") < Format([Birthdate], "mmdd"))

End Sub
 

Users who are viewing this thread

Back
Top Bottom