DOB Calculation in form

  • Thread starter Thread starter azzie_B
  • Start date Start date
A

azzie_B

Guest
Hi Guys this should be a relatively easy one for you, I have a form in which I have a Date of Birth Field and have used the following in the Control Source of an unbound textbox:

= DateDiff("yyyy",[DOB],Date())+(Date()<DateSerial(Year(Date()),Month([DOB]),Day([DOB])))

to calculate the age automatically,

It works fine and everything but when I check the table the DOB has been added but the age field is empty.

Any ideas :confused: :confused: :confused:
 
hi ,,
i used to have same problems... and i made myself the following solution

1. make a macro
2. Action = SetValue

item...........your age field
expression.......... your textbox field which has the calculated field

save the macro and run it on the afterupdate event of the Birthdate field.

this would copy the field fom you textbox calculated field to the origional Age field. dont forget to makethe calculated texbox field hidden

hope this would help
 
1. There is no reason to make a macro to do this. A macro just complicates the process. If you ever need to store a calculated value, you need only a single line of VBA code!
Me.FieldYouWantToStore = Me.CalcControl
The code goes into the Form's BEFORE update event.
2. You should NOT store the calculated Age. It may be invalid TOMORROW!!! Always calculate age in your query or form.
 

Users who are viewing this thread

Back
Top Bottom