Solved: Access Table and Report

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

computerman29642

Thread Starter
Joined
Dec 4, 2007
Messages
2,895
I have an Access Table that contains two date type fields. Sometimes one date field will have data and the other will not have any data. Other times they will both have data.

I need a way to display both date fields on a report without having two different fields on the report. What I would like happen, if the second date field is blank/empty/null then display the first date field. If they both contain a date, then display the second date field.

I tried placing a textbox on the report with the following:

Code:
iif(Datefield2 = "", Datefield1, Datefield2)
That did not work. Can someone please guide me in the right direction.
 

OBP

Joined
Mar 8, 2005
Messages
19,895
Depending on where it is on the Report you can use some VBA in the Header/Details "On Format Event Procedure".
Something like
if isnull(me.datefield2) then
me.reportdate = me.datefield1
else
me.reportdate = me.datefield2
end if
where reportdate is the real name of your unbound text box.
 
Joined
Oct 20, 2004
Messages
7,837
or, IIf(IsNull([datefield2]),[datefield1],[datefield2]) works in a query - probably will in a report too.
Just tried it - yep!
 

computerman29642

Thread Starter
Joined
Dec 4, 2007
Messages
2,895
Depending on where it is on the Report you can use some VBA in the Header/Details "On Format Event Procedure".
Something like
if isnull(me.datefield2) then
me.reportdate = me.datefield1
else
me.reportdate = me.datefield2
end if
where reportdate is the real name of your unbound text box.
Thanks, OBP. :)
 
Joined
Oct 20, 2004
Messages
7,837
The VBA would be faster, if there are a lot of dates, but if both dates are empty (don't know if that is possible or not) the VBA would throw you an error (I think), while the formula will just return a blank box.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top