Here is a copy of the code that I use in very limited circumstances. My
subform is always the bottom most control on the form and is in the detail
section. I may have a more current version, but I can't locate it.
Public Sub GrowSubForm(sfrmControl As Control)
'===============================================================================
' Procedure : GrowSubForm
' Created : 9/15/2005 12:42
' Author : John Spencer
' Purpose : Expands/Shrinks the detail section and the subform to conform to
' the available size of the detail section of the Parent form window
' There should not be any controls below the subform
'===============================================================================
Dim lngWindowHigh As Long, lngHeaderHigh As Long, lngFooterHigh As Long
Dim lngMargin As Long
Dim frmAny As Form
Set frmAny = sfrmControl.Parent
On Error GoTo ERROR_GrowSubForm
'---------------------------------------------------------------
' Code Change Needed: Should check for the existence of the
' form header and footer sections and the visibility of the sections.
' Also check for page header and page footers (and visibility)
'---------------------------------------------------------------
lngWindowHigh = frmAny.InsideHeight
lngHeaderHigh = frmAny.Section(acHeader).Height
lngFooterHigh = frmAny.Section(acFooter).Height
lngMargin = frmAny.Section(acDetail).Height - sfrmControl.Height
'Debug.Print lngWindowHigh, lngHeaderHigh, lngFooterHigh, lngMargin, _
lngWindowHigh - lngHeaderHigh - lngFooterHigh, _
frmAny.Section(acDetail).Height
If lngWindowHigh - lngMargin - lngFooterHigh - lngHeaderHigh < 0 Then
'Do nothing as this would cause an error
ElseIf frmAny.Section(acDetail).Height < _
lngWindowHigh - lngHeaderHigh - lngFooterHigh Then
frmAny.Section(acDetail).Height = _
lngWindowHigh - lngHeaderHigh - lngFooterHigh
sfrmControl.Height = frmAny.Section(acDetail).Height - lngMargin
' Debug.Print "enlarged"
ElseIf frmAny.Section(acDetail).Height > _
lngWindowHigh - lngHeaderHigh - lngFooterHigh Then
sfrmControl.Height = _
lngWindowHigh - lngMargin - lngFooterHigh - lngHeaderHigh
frmAny.Section(acDetail).Height = _
lngWindowHigh - lngHeaderHigh - lngFooterHigh
' Debug.Print "shrank"
Else
' Debug.Print "maintained"
End If
EXIT_GrowSubForm:
On Error GoTo 0
Exit Sub
ERROR_GrowSubForm:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
" in procedure GrowSubForm of ModFunctions"
sfrmControl.Height = _
lngWindowHigh - lngHeaderHigh - lngFooterHigh - lngMargin
frmAny.Section(acDetail).Height = _
lngWindowHigh - lngHeaderHigh - lngFooterHigh
End Sub
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County