2005-01-12, 21:29 #1
- Join Date
- Jun 2002
- Michigan City, Indiana, USA
- Thanked 0 Times in 0 Posts
Print control on report only if not null (2003)
I have a form that staff fill out when a student takes a test. The results of this form go into a report. One of my controls is TIrr (testing irregularities). I would like this control to only print on the report if this control has something in it, i.e., is not null. I am very inexperienced with code so full code would be very helpful. Currently, I have a button on my form that brings up the report and automatically prints it. Any help would be much appreciated.
Subscribe to our Windows Secrets Newsletter - It's Free!
Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!
+ Get this BONUS — free!
Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!
2005-01-12, 21:41 #2
- Join Date
- Mar 2002
- Thanked 16 Times in 16 Posts
Re: Print control on report only if not null (2003)
If you have a series of text boxes below each other (on a report), you can set the Can Shrink property of a text box and of the section containing it (probably the Detail section) to Yes. If the value of the text box is Null, it will not be displayed or printed, and the controls below it will move up so that no blank space is left.
This doesn't help if your controls are organized differently. You can use code in the On Format event of the section containing the control (probably the Detail section) to hide it if it is Null:
- Open the report in design view.
- Click on the horizontal gray bar at the top of the section containing the control.
- Activate the Event tab of the Properties window.
- Click in the On Format box.
- Select [Event Procedure] from the dropdown list.
- Click the ... to the right of the dropdown arrow.
- The Visual Basic Editor will be activated, and the insertion point will be in a blank line between the first and last line of the event procedure that has been created for you.
- Press tab, and type <code>Me.TIrr.Visible = Not IsNull(Me.TIrr)</code> where TIrr is the name of the text box.
- The procedure should now look like this:
Private Sub Details_Format(Cancel As Integer, FormatCount As Integer)
Me.TIrr.Visible = Not IsNull(Me.TIrr)
- Switch back to Access (Alt+F11)