| Forms |
| 3.4 Making Forms Adjust Their Size to Their Contents in Access 97. |
| Charlotte Foust, Direct Marketing Partners of Sacramento, California US. |
I've used this routine for some time in Access 97 to make my forms adjust their size to their contents. However, I decided to apply it to a multipage form and needed to enhance the routine so that I could pass it the specific height I wanted to use to display only one page at a time. As long as I was at it, I added the same functionality for form height. Here's the resulting code:
Sub glrResetWindowSize(frm As Form, Optional intTotalFormHeight, Optional intTotalFormWidth)
' copied originally from Access Help files
' modified by Charlotte Foust
Dim intWindowHeight As Integer
Dim intWindowWidth As Integer
Dim intHeightHeader As Integer
Dim intHeightDetail As Integer
Dim intHeightFooter As Integer
' Determine form's height.
If IsMissing(intTotalFormHeight) Then
intHeightHeader = frm.Section(acHeader).Height
intHeightDetail = frm.Section(acDetail).Height
intHeightFooter = frm.Section(acFooter).Height
intTotalFormHeight = intHeightHeader + intHeightDetail + intHeightFooter
End If
' Determine form's width.
If IsMissing(intTotalFormWidth) Then
intTotalFormWidth = frm.Width
End If
' Determine window's height and width.
intWindowHeight = frm.InsideHeight
intWindowWidth = frm.InsideWidth
If intWindowWidth <> intTotalFormWidth Then
frm.InsideWidth = intTotalFormWidth
End If
If intWindowHeight <> intTotalFormHeight Then
frm.InsideHeight = intTotalFormHeight
End If
End Sub
The routine can be called by inserting the following line in the Form_Open event procedure:Call glrResetWindowSize(Me) If I want to set the form to a particular height, I add the specific height or Me.InsideHeight as the second argument. Coding in the specific height means I don't have to worry about the form size changing each time I edit the form's design. |