Hide Error in Calculated Age Field when no DOB entered?

S

scs

I have the following calculated field in a query. It works great except
when I don't have a Date of Birth entered. Then it displays Err. Is there
a way to display something different or nothing at all? Or is there a way
to display it differently on a form?

Here is the formula I am using:

Age:
IIf(Int(Format([DOB],"y"))>Int(Format(Date(),"y")),DateDiff("yyyy",[DOB],Date())-1,DateDiff("yyyy",[DOB],Date()))

TIA
Steve
 
G

Guest

Hi scs, try:

IIf(Nz([DOB]),"
",IIf(Int(Format([DOB],"y"))>Int(Format(Date(),"y")),DateDiff("yyyy",[DOB],Date())-1,DateDiff("yyyy",[DOB],Date())))

I haven't tested it but in plain language it should read like this:

If DOB is null, then display a zero-length string, else if DOB is greater
than the current date, then perform 1st calculation, else calculate the 2nd
calculation

Let me know the outcome.
 
D

Douglas J Steele

I think you mean IsNull, not Nz.

What you've got would work, but it's backwards: if DOB is null, it'll be
assigned a value of 0 which is False, whereas non-null DOBs would be
non-zero, and hence True.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


xRoachx said:
Hi scs, try:

IIf(Nz([DOB]),"
",IIf(Int(Format([DOB],"y"))>Int(Format(Date(),"y")),DateDiff("yyyy",[DOB],D
ate())-1,DateDiff("yyyy",[DOB],Date())))

I haven't tested it but in plain language it should read like this:

If DOB is null, then display a zero-length string, else if DOB is greater
than the current date, then perform 1st calculation, else calculate the 2nd
calculation

Let me know the outcome.


scs said:
I have the following calculated field in a query. It works great except
when I don't have a Date of Birth entered. Then it displays Err. Is there
a way to display something different or nothing at all? Or is there a way
to display it differently on a form?

Here is the formula I am using:

Age:
IIf(Int(Format([DOB],"y"))>Int(Format(Date(),"y")),DateDiff("yyyy",[DOB],Dat
e())-1,DateDiff("yyyy",[DOB],Date()))
TIA
Steve
 
G

Guest

Good catch Douglas! That's what I get for answering questions when I'm
tired. :)

Douglas J Steele said:
I think you mean IsNull, not Nz.

What you've got would work, but it's backwards: if DOB is null, it'll be
assigned a value of 0 which is False, whereas non-null DOBs would be
non-zero, and hence True.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


xRoachx said:
Hi scs, try:

IIf(Nz([DOB]),"
",IIf(Int(Format([DOB],"y"))>Int(Format(Date(),"y")),DateDiff("yyyy",[DOB],D
ate())-1,DateDiff("yyyy",[DOB],Date())))

I haven't tested it but in plain language it should read like this:

If DOB is null, then display a zero-length string, else if DOB is greater
than the current date, then perform 1st calculation, else calculate the 2nd
calculation

Let me know the outcome.


scs said:
I have the following calculated field in a query. It works great except
when I don't have a Date of Birth entered. Then it displays Err. Is there
a way to display something different or nothing at all? Or is there a way
to display it differently on a form?

Here is the formula I am using:

Age:
IIf(Int(Format([DOB],"y"))>Int(Format(Date(),"y")),DateDiff("yyyy",[DOB],Dat
e())-1,DateDiff("yyyy",[DOB],Date()))
TIA
Steve
 
S

scs

Thanks for the great tip! I appreciate the help. Works perfect. Thanks to
Douglas too.

xRoachx said:
Hi scs, try:

IIf(Nz([DOB]),"
",IIf(Int(Format([DOB],"y"))>Int(Format(Date(),"y")),DateDiff("yyyy",[DOB],Date())-1,DateDiff("yyyy",[DOB],Date())))

I haven't tested it but in plain language it should read like this:

If DOB is null, then display a zero-length string, else if DOB is greater
than the current date, then perform 1st calculation, else calculate the
2nd
calculation

Let me know the outcome.


scs said:
I have the following calculated field in a query. It works great except
when I don't have a Date of Birth entered. Then it displays Err. Is
there
a way to display something different or nothing at all? Or is there a
way
to display it differently on a form?

Here is the formula I am using:

Age:
IIf(Int(Format([DOB],"y"))>Int(Format(Date(),"y")),DateDiff("yyyy",[DOB],Date())-1,DateDiff("yyyy",[DOB],Date()))

TIA
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top