Calculated field error (1 Viewer)

corneliud

New member
Local time
Today, 17:55
Joined
Oct 20, 2020
Messages
5
In a query I have a calculated field which outputs the age taking into account the date of birth. Sometimes it works and I can see the age in the query sometimes it doesn't work (especially after saving the database) and I get an #Error. How can i overcome this?

Best regards,

Corneliu Dimitriu
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:55
Joined
Oct 29, 2018
Messages
21,449
Hi. Welcome to AWF!

My guess would be, when it doesn't work, the birthdate might be missing. If so, you could try using the Nz() function in your calculation.
 

corneliud

New member
Local time
Today, 17:55
Joined
Oct 20, 2020
Messages
5
Hi. Welcome to AWF!

My guess would be, when it doesn't work, the birthdate might be missing. If so, you could try using the Nz() function in your calculation.
The error appears for the whole field. No, none of the birthdays are missing.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:55
Joined
May 7, 2009
Messages
19,231
what is your formula:

Age: DateDiff("yyyy", DOBField, Date()) + (DatePart("y", Date()) < DatePart("y", DOBField))
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:55
Joined
Feb 28, 2001
Messages
27,133
If neither date is missing, then the only other issue is, what data type are those fields? If they are not both "Date" fields but rather one or the other is of type "Short Text" then your error would be a non-conforming input.

Offhand, that formula looks OK because you are not trying to format it as anything other than an integer. Therefore, the hidden "gotcha" situations that crop up in date conversions don't appear to apply here.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:55
Joined
May 7, 2009
Messages
19,231
Age: DateDiff("yyyy", Nz([Date of Oncall], Date()), [Date of Birth])
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:55
Joined
May 7, 2009
Messages
19,231
reverse the position of the fields:

Age: DateDiff("yyyy", [Date Of Birth], Nz([Date of Oncall], Date()))
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:55
Joined
May 7, 2009
Messages
19,231
you are welcome!
 

Users who are viewing this thread

Top Bottom