Search code examples
ms-accessvbams-access-2003

Dynamically resize a report Detail area


Is it possible to resize the Detail area of a report dynamically, in MS Access?

I have a report and the Detail region has 2 rows, I'd like one of them to be "optional" - when there is no data it should not display and the Detail region should only be as tall as the top row of data.

I have code like this:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Dim reduceHeight As Integer
    reduceHeight = Me.Label83.Height


    If IsNull(Me.data_1) Then
        Me.data_1.Visible = False
        Me.Label83.Visible = False
    Else
        Me.data_1.Visible = True
        Me.Label83.Visible = True
    End If

    If IsNull(Me.data_1) 
        Detail.Height = Detail.Height - reduceHeight
    End If

End Sub

And it works as far as makign the label and text box conditionally visible, but I can't get the Detail region to shrink when the bottom line is hidden. I did set the CanShrink property for the Detail to True, but it doesn't shrink.


Solution

  • Set CanShrink for your controls too (e.g. textboxes):

    enter image description here enter image description here