Full Version: How To Omit Blank Fields In The Report
UtterAccess Discussion Forums > Microsoft® Access > Access Reports
infobroker
Dear,

I have the table with following fields: Authors, Title, Description, Other_names, Other_titles. I would like to create reports consisting all mentioned fields, but some fields are sometimes blank, e.g. Other names or Other titles. Is there a way to omit these blank fields in the final rtf report?

I would very appreciate for your help.

Regards,

Adam
pere_de_chipstick
Hi Adam

How do you mean by 'Omit them'?

To reduce any vertical space you could sert the Can gow and Can Shrink propreties of the text boxes:
1. If you have any labels associated with these fields you need to replace them with text boxes
2. For these label text boxes you will need to set the Control source to =IIF([SomeFieldName]="","","TheLabelText")
3. Set the Can Grow and Can Shrink properties of all the text and 'label' text boxes to 'Yes':
4. Set the Can Grow and Can Shrink properties of the report section the text boxes appear in, to 'Yes'

This will reduce the vertical size of the section they appear in, if the fields are vertical placed (e.g.):
QUOTE
Author: Isaac Asimov
Title: I Robot
Description: Sci Fi,
Other_names:
Other_titles: Caves of Steel, Foundation, ....


Then any blank lines would disappear e.g. the above 5 lines would appear as
QUOTE
Author: Isaac Asimov
Title: I Robot
Description: Sci Fi,
Other_titles: Caves of Steel, Foundation, ....


However e.g. if the record looks like:
Authors, Title, Description, Other_names, Other_titles
ie, in a horizontal line, then if there is any text in any of these fields there will be no effect.

You could use code to reposition and resize each of the text boxes but IMHO this would probably not be worth the effort!

hth
doctor9
Adam,

Since this report is going to be output to .RTF format, there's one way you could do it I can think of.

Create a new query field in the query that drives the report, called "strOutput". This will be a calculated field with this sort of calculation:

=[Authors] & vbCrLf & [Title] & vbCrLf & [Description] & vbCrLf & Nz([Other_names], "") & vbCrLf & Nz([Other_titles], "")

The "vbCrLf" bit is a shortcut for "Carriage Return/Line Feed", or "start a new line of text".

This is assuming that each field is currently on it's own line in the report. If you have Authors and Title on the same line, you can replace vbCrLf with a single space like this: " "

Now, since you might end up with two "new lines" in a row, you need to create a second calculated field that deals with that;

strOutputFixed: Replace([strOutput],[vbCrLf] & [vbCrLf],[vbCrLf])

This should clean up your output. Note: At this point, I'm assuming that the only fields that might be empty are "other names" and "other titles". If I'm wrong, let me know.

Open your query in Datasheet view, and expand the row height to see the multiple rows, to make sure it looks right to you.

Once you've got your calculated fields done, go to the report and remove all of the textboxes bound to the fields you've now consolidated into a single calculated field. Create a single textbox that is bound to strOutputFixed. Make sure it's wide enough to display the widest possible text, but only make it ONE line of text tall. Set the Can Grow property of this textbox to TRUE.

Now the report will expand the textbox vertically to make it as tall as it needs to be, leaving no blank lines in the middle of a record. That should do it.

Hope this helps,

Dennis
infobroker
Hi Bernie and Dennis,

thank you very much for your responses and advices. They are extremely valuable for me.

Kind regards,

Adam
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.