Change subform height at runtime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form in Access XP(2002) that contains an unbound subform when it is
initially opened. There are also 15 buttons on the form that will each load
a different subform when clicked. All of the subforms are the same width but
each have a different height. I would like to be able to adjust the height
of the subform control on the main form to be slightly larger than the
subform that is loaded when one of the buttons are clicked.

I know that I could just look up each subform's height and hard code it
under each button, but I would like to retrieve the subform's height in code
and set it that way.

I've looked into reteiving the subforms height using the AllForms collection
with something like this:
lgnHeight =
CurrentProject.AllForms("SubFormName").Properties("Height").Value

but I get the error: "2455: You entered and expression that has an invalid
reference to the property 'Height'.

Can anyone give me some insight on how to find a form's height in the
database before it is loaded or find a subform's height (not the control)
once it is loaded?

Thanks.
 
Sasquatch said:
I have a form in Access XP(2002) that contains an unbound subform when it is
initially opened. There are also 15 buttons on the form that will each load
a different subform when clicked. All of the subforms are the same width but
each have a different height. I would like to be able to adjust the height
of the subform control on the main form to be slightly larger than the
subform that is loaded when one of the buttons are clicked.

I know that I could just look up each subform's height and hard code it
under each button, but I would like to retrieve the subform's height in code
and set it that way.

I've looked into reteiving the subforms height using the AllForms collection
with something like this:
lgnHeight =
CurrentProject.AllForms("SubFormName").Properties("Height").Value

but I get the error: "2455: You entered and expression that has an invalid
reference to the property 'Height'.

Can anyone give me some insight on how to find a form's height in the
database before it is loaded or find a subform's height (not the control)
once it is loaded?


A form's Height is determined by the sum of it's header,
footer and detail height.

If the subform is displayed in Continuous view, then you
will have to multiply the detail height by the number detail
records you want to display.

If there's a chance that a form does not have the
header/footer sections, use error handling to deal with it.

For a Single view form, a rough idea of the code would be
like:

Dim lngHdrFtrHgt As Long
On Error ResumeNext
With Me.subformcontrol
.SourceObject = "name of some form"
lngHdrFtrHgt = .Form.Section(1).Height _
+ .Form.Section(2).Height
lngHdrFtrHgt = lngHdrFtrHgt + .Form.Section(0).Height
.Height = lngHdrFtrHgt
End With
 
Back
Top