Yotam
Yotam

Reputation: 10485

Printing non-null fields only in MS Access 2003 report

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:

  1. This doesn't seem like the smartest way to do it. Anyone has a better idea?
  2. The report also contains check-boxes, and this method only works if I check/uncheck at least one check-box before I generate the report. Otherwise all captions appear anyway. This is very weird - anyone has any idea why it happens?

Upvotes: 1

Views: 815

Answers (1)

Fionnuala
Fionnuala

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

Related Questions