Resize form in MS Access by changing Detail.Height

2019-07-15 08:47发布

I want the user to be able to change the height of the form while in Form View by clicking a button:

Private Sub btnChangeHeight_Click()

    booTall = Not booTall

    If booTall Then
        lngHeight = 12400   ' (twips)
    Else
        lngHeight = 1200
    End If

    Me.Detail.Height = lngHeight
    Me.Repaint

    Debug.Print Me.Detail.Height

End Sub

The height changes -- Debug.Print says so, and a vertical scroll bar appears when booTall is True. But the form won't change its vertical dimension onscreen.

I also tried this, without success (making sure my button was on the Form header):

    Me.Detail.Visible = booTall

The solution would seem to depend on properties for the Form and Form Detail section: Resizable, Auto Height, perhaps Can Grow, etc. But I've fiddled with those and nothing works.

I understand overlapping controls and other things can prevent height adjustments, so I've reduced the form to a minimal layout. I'm using Access version 2007/2010.

Some additional info: What I actually am working toward is two subforms, (A) above and (B) below, which can independently be collapsed out of view or expanded. This is for a decision-making form with a LOT of data on it. I thought if I collapsed the height of (A) or (B), the CanShrink property of Detail would cause the overall form dimension to change. In fact, I think I did this a few years ago using Access 2003. As for using Maximize ... we're setting up this form as re-usable, multiple instances can open.

2条回答
欢心
2楼-- · 2019-07-15 09:32

" ... change the height of the form while in Form View by clicking a button"

Use the form's .Move method to change the form's size. This sample toggles my form's height between 4044 and 8000 twips.

Private Sub btnChangeHeight_Click()
    Dim lngHeight As Long

    If Me.WindowHeight = 4044 Then
        lngHeight = 8000
    Else
        lngHeight = 4044
    End If
    Me.Move Me.WindowLeft, Height:=lngHeight
End Sub
查看更多
放荡不羁爱自由
3楼-- · 2019-07-15 09:39

I have had a similar problem and found that even if I hid the fields (controls) I didn't want to see the Detail height would not shrink enough. I found if I moved the controls I wanted to hide (so set both .Visible and .Top properties) then Detail.Height would reduce to what I wanted. It's as though even hidden Access refused to ignore the hidden controls

查看更多
登录 后发表回答