How do I get a report to print the contents of 'FieldA' ....

G

Guest

I'm new to Access and hope someone can help.
How can I get a report to print the contents of one field only if
there has been an entry in another field?
Also
how do I get the contents of a field to print only if the entry
is between two limits (eg date of birth is printed only if the
person was born after 1986)

Thanks
 
D

Duane Hookom

The easiest method might be using IIf() in the control source.
=IIf({some condition is true}, [What To Show],"")
 
G

Guest

Do you mean that you only want records matching your criteria displayed on the report?
If this is case you would want to filter the report based on criteria you set - this can be found in the report's properties (in design view).

If you mean that you want the contents of the field for each record to only be shown if it matches criteria, then you would put a formula in the field:

eg lets say you have a record like this:

NAME DOB DIABETIC? MEDICATION
Brian Toms 1/1/1990 Yes Insulin

If you only want the DOB displayed if it is after 1986, in design view go to the textbox containing DOB in the detail section and where it says the field name (for date of birth), replace it with a formula like this:
=IIf(Year([DOB])<1986,"",[DOB])

If you only want MEDICATION displayed if the DIABETIC field has been populated, in the MEDICATION textbox you can do something like:
=IIf(IsNull([DIABETIC]),"",[MEDICATION])

PS If you are actually only interested in showing the DOB for people under 18, I would say you use a formula like this so that you don't have to keep updating the 1986 bit:
=IIf(IIf(IsNull([DOB]),"",Year(Now())-Year([DOB])+(DateSerial(Year(Now()),Month([DOB]),Day([DOB]))>Now()))<18,"",[DOB])

Basil
 
G

Guest

Thank you & Basil for your swift responses, but I'm afraid I am still having
problems.
As I say I'm very new to Access, and although I entered your suggestions
in the Control Source, the result is #Error in the report.
I've tried putting all sorts of heiroglyphs in the statement (#,",')etc but
to no avail.
The very long string is just what I want (dob to show only if the person
is under 18), but that too gives me a #error.

I'm sure it's something basic I'm doing wrong, but unfortunately don't
know what it is.

Any further help will be appreciated.



Duane Hookom said:
The easiest method might be using IIf() in the control source.
=IIf({some condition is true}, [What To Show],"")


--
Duane Hookom
MS Access MVP


Maggie said:
I'm new to Access and hope someone can help.
How can I get a report to print the contents of one field only if
there has been an entry in another field?
Also
how do I get the contents of a field to print only if the entry
is between two limits (eg date of birth is printed only if the
person was born after 1986)

Thanks
 
D

Duane Hookom

Make sure the name of the control is not also the name of a field. If you
still have issues, come back with your expression or all field names and
"rules".

--
Duane Hookom
MS Access MVP
--

Maggie said:
Thank you & Basil for your swift responses, but I'm afraid I am still having
problems.
As I say I'm very new to Access, and although I entered your suggestions
in the Control Source, the result is #Error in the report.
I've tried putting all sorts of heiroglyphs in the statement (#,",')etc but
to no avail.
The very long string is just what I want (dob to show only if the person
is under 18), but that too gives me a #error.

I'm sure it's something basic I'm doing wrong, but unfortunately don't
know what it is.

Any further help will be appreciated.



Duane Hookom said:
The easiest method might be using IIf() in the control source.
=IIf({some condition is true}, [What To Show],"")


--
Duane Hookom
MS Access MVP


Maggie said:
I'm new to Access and hope someone can help.
How can I get a report to print the contents of one field only if
there has been an entry in another field?
Also
how do I get the contents of a field to print only if the entry
is between two limits (eg date of birth is printed only if the
person was born after 1986)

Thanks
 

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