programmatically changing size of continuous forms

J

JohnB

I know you are not supposed to double post, but I accidentally posted first
to a newsgroup that appears to be no longer active
(microsoft.public.access.formsprogramming). So, I am trying here as well.

I've tried searching the internet in a variety of ways to get this one, but
can't find it. I have a continuous form that opens at first with no records
and the Detail section's visible property set to No. The user selects a
criteria from the combo box (e.g., cboCriteria) in the header, the
after_update event of which goes something like this:
lngID=me.cboCriteria
strSQL="SELECT * FROM tblMyTable WHERE ID=" &
lngID
me.recordsource=strSQL
me.Detail.visible=true
docmd.RunCommand acCmdSizeToFitForm

The above code does NOT seem to change the size of the form. What I
want to happen, if this is possible, is for the form to expand or shrink
depending on the number of records to be displayed in the Detail section,
and for the area displaying the data to grow or shrink each time the user
selects a new value from the combo box. The number of records to be
returned after each selection from the combo box varies only from 0 to 18,
so the form only needs to expand or shrink a few inches of screen height.
Is this possible?

I have wondered about this for years, and usually just find a way around it.
But now I just want to know. Thanks. --John
 
D

Dale Fye

John,

You can change the forms height by using the InsideHeight property of the
form. Figure out the height of a single record in the detail section
(HtSnglRec) and multiply that by the number of records returned

So, instead of the DoCmd.RunCommand entry, try

me.insideheight = me.section(1).height + me.section(2).height +
(me.recordsetclone.recordCount * HtSnglRec) * 1440

You might want to set the maximum height for the detail section, so you
don't end up with too many records displayed at once. If you do this, you
will want to make sure that you display the vertical scrollbar as well.

Dim intDetRows as integer
if me.recordsetclone.recordcount > 5 then
intDetRows = 5
me.scrollbars = 2
else
intDetRows = me.recordsetclone.recordCount
me.scrollbars = 0
endif
me.insideheight = me.section(1).height + me.section(2).height + (intDetRows
* htSnglRec) * 1440

The challenge with this is not to make the form extend off of the screen.
There is a way to determine the height of your screen and reposition the
form so that it is centered vertically, but I'll have to do some research to
remember how. I think there is an API call or two involved.

HTH
Dale
 

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