Form field with expression not storing in Table?

texzen123

New member
Local time
Today, 06:19
Joined
Oct 20, 2008
Messages
8
Hello,
I hope my problem isn't so small that it's offensive, but I've bought every book I can afford (as a newbie) and I can't figure where I'm missing it.

  • I have small Table w/ 3 fields [Name] [Date of Birth] and [Age]
  • I used the wizard and made a simple form using the same 3 fields to enter the data.
  • On the [Age] field of the form I added the "DateDiff" expression to convert the date to age, and it works great in the form, but it doesn't store the data in the Main Table.
Can someone please tell me where I am missing it?

I am eternally grateful and Thanks So MUCH in advance!
Have a great day!
 
Actually you're probably not missing anything! Unless the age is going to be static, i.e. you're using it for something "age at onset of symptoms" or "age when first incarcerated" this type of calculation shouldn't be stored in the underlying table! Instead, it should be re-calculated whenever needed, such as each time you access the record or when creating a report.
 
Thank You! Yes, it [Age] is going to be used to generate potential error messages for future reference. I didn't know how to make the form store that data.
Is that a possibility?
Thank You So Very Much!
:)
 
Thank You! Yes, it [Age] is going to be used to generate potential error messages for future reference. I didn't know how to make the form store that data.
Is that a possibility?
Thank You So Very Much!
:)
You still shouldn't store age. Just calculate it when you need it. It won't be accurate tomorrow if you store it.
 
Thank You.
I needed this value to determine a loan approval /decline at the time of application. A contract with a minor is invalid. If the [Age] at the time of applying was >18, we are going to have to decline the application.
If it is <18, then the applicant may continue.

Thanks!
:)
 
Ok, it's mandatory that ae be stored in the field-no way aroun it.
Is there a way it can be done?
 
Sure. You don't say how/where you're doing your calculation presently. If you've put it in the Control Source for the Age field, take it out. The textbox that holds the result has to be bound to the field in the underlying table that you want to hold the age.

Select the age textbox, then goto Properties - Data and in the Control Source property box select the Age field. Then use this code, replacing DateOfBirth with the exact name of your textbox:

Code:
Private Sub DateOfBirth_AfterUpdate()
  Me.Age = DateDiff("yyyy", [DateOfBirth], Date) - IIf(Format$(Date, "mmdd") < Format$([DateOfBirth], "mmdd"), 1, 0)
End Sub

And, BTW, in your post

If the [Age] at the time of applying was >18, we are going to have to decline the application. If it is <18, then the applicant may continue.
you've got your operators backwards!

> 18 means greater than 18

< 18 means less than 18

which is the opposite of what you posted.
 

Users who are viewing this thread

Back
Top Bottom