How to Obtain the Height of a Form?

K

Kevin Myers

How can one obtain obtain the height of a MS Access 2K form?

There is a width property, but I don't see a corresponding height property.
I need to obtain the height of the form so that I can dynamically resize an
object on the form in the form's Form_Resize method when a user resizes the
form, both horizontally and vertically.

Thanks,
s/KAM
 
B

Bri

Kevin,

The total Height of a Form is the sum of the Height of all of the
Sections (Form Header/Footer) and the Detail(s) so there is no one place
for it. If the Height of your headers and footers are contant and you
are not using a continous form then you can add the Detail section to
your header/footer heights. Also, keep in mind that the Height (and
Width) are actualy stored as Twips (1440 twips = 1 inch).

From the Help:

· The Height property applies only to form sections and report sections,
not to forms and reports.
· The Width property applies only to forms and reports, not to form
sections and report sections.
· Both properties apply to controls on forms and reports.

The height of sections and the width of forms and reports are measured
from the inside of their borders.


Air Code
========

For I=0 to 4 '(the five sections of a Form, Report has nine)
lTotalTwips = lTotalTwips + Me.Section(I).Height
Next

Msgbox "The total Height of the Form is: " & _
lTotalTwips /1440 & " Inches"

=========

The Section Properties are read only.

If the object you want to resize is in the Detail Section and you want
it to be a ratio of the Detail Height then:

Air Code
========

'Assume object is to be 50% of the height of the Form Detail Section
Me.MyObject.Height = Me.Section(0).Height / 2

=========

Hope that helps

Bri
 
K

Kevin Myers

Thanks to both Allen and Bri for their very helpful comments. Based on what
they said, here is what I put in the code for my form:

Private Sub Form_Resize()
If (Me.Width / 1440) <= 10 Then ImgEdit1.Width = 4.9167 * 1440 Else
ImgEdit1.Width = Me.Width - 5.0833 * 1440
If (Detail.Height / 1440) <= 7.5 Then ImgEdit1.Height = 7.3333 * 1440 Else
ImgEdit1.Height = Detail.Height - 0.1667 * 1440
End Sub

Unfortunately this still isn't working. The method does seem to be
executing when the form is resized, but the values of Me.Width and
Detail.Height don't seem to be changing. In the properties for the form the
Default View is set to Single Form, Auto Resize is set to No and Border
Style is set to Sizable. In properties for the Detail section, Can Grow and
Can Shrink are both set to Yes, while for the Form Header and Form Footer
sections these properties are both set to No.

What am I overlooking?

Thanks,
s/KAM
 
A

Allen Browne

Hi Kevin.

Right: if you physically drag the window size such that it is bigger than
the height of of the sections, then the height of the window has no
relationship to the height of the sections.

Stephen Lebans has a free downloadable example showing " a Form that
demonstrates the relationships of the Form and Section Height and Width
properties" in this link:
http://www.lebans.com/formdimensions.htm
 
K

Kevin Myers

Thanks for confirming my observations Allen. After further trial and error,
the following seems to be doing what I want fairly well. I'd appreciate it
if anyone would let me know if they see any obvious pitfalls to this
approach (note that my Form Header and Form Footer sections have a height of
zero):

Private Sub Form_Resize()
Me.Width = Me.InsideWidth - 0.25 * 1440
Detail.Height = Me.InsideHeight - 0.25 * 1440
If (Me.Width / 1440) <= 10 Then ImgEdit1.Width = 4.9167 * 1440 Else
ImgEdit1.Width = Me.Width - 5.0833 * 1440
If (Detail.Height / 1440) <= 7.5 Then ImgEdit1.Height = 7.3333 * 1440 Else
ImgEdit1.Height = Detail.Height - 0.1667 * 1440
ImgEdit1.FitTo 1
End Sub


Regards,
s/KAM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top