Reputation: 10485
I am trying to generate a report whose source is a form and that only prints fields that are not null.
To do so I have two text-boxes for every field. They are both resizealbe (can shrink/grow). The first text-box is for the caption, and its source is
=IIf([record] Is Null,"","Caption:")
The second is the record value itself. If record is null then the value of both text-boxes is "" and null and they do not appear nor take any space in the form.
Two question:
Upvotes: 1
Views: 815
Reputation: 91366
This will only work properly with Print Preview, not MS Access 2010 report or layout view. You will need Can Shrink on the control to close up the gaps. In Access 2010, "*_Label" is the default name assigned to labels of controls.
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acLabel And ctl.Name Like "*_Label" Then
ctl.Visible = Not IsNull(ctl.Parent)
''Bound checkboxes are never null, so hide false
If ctl.Parent.ControlType = acCheckBox Then
ctl.Visible = ctl.Parent
ctl.Parent.Visible = ctl.Parent
End If
End If
Next
End Sub
Upvotes: 1