Height of the subform adjusted by the number of records

Faoineag

Registered User.
Local time
Today, 07:43
Joined
Jan 7, 2018
Messages
99
Good morning, I have a mask with 2 continuous subforms inside that report data from a query. Each in each record of the main form can contain one, two or more rows. I would like the height of each subform to be proportional to the number of rows (if the subform A has a record of a height, if the subform B has 3 records it will have a greater height).I tried to insert on the Current event of the main form the code indicated here on this forum (sorry I'm not going to put the link):
me.subformname.height = me.subformname.form.section (0) .height * (me.subformname.form.count + 1)
indicating only one of the two subforms to try, but unfortunately the height of the subform is increased a lot. Not being an expert on vba I wonder if this may depend on the fact that on Current of the mask I already have another code, to which I added this below. Thank you
 
I tried to insert on the Current event of the main form the code indicated here on this forum (sorry I'm not going to put the link):
me.subformname.height = me.subformname.form.section (0) .height * (me.subformname.form.count + 1)

It would help us help you if you did provide the link!

Have you tried just setting the Can Grow property to Yes?

NOTE: if code is needed, be aware measurements in Access are often based on units called twips so you may need to factor that into your code. 1440 twips =1 inch ; 567 twips/cm

BTW what does this mean?
I have a mask with 2 continuous subforms
 
It would help us help you if you did provide the link!

Have you tried just setting the Can Grow property to Yes?

NOTE: if code is needed, be aware measurements in Access are often based on units called twips so you may need to factor that into your code. 1440 twips =1 inch ; 567 twips/cm

BTW what does this mean?

Yes I set up Can Gow yes, but nothing changes, the subform becomes large (fixed height) regardless of the number of records
 
It would help us help you if you did provide the link!

Have you tried just setting the Can Grow property to Yes?

NOTE: if code is needed, be aware measurements in Access are often based on units called twips so you may need to factor that into your code. 1440 twips =1 inch ; 567 twips/cm

BTW what does this mean?
Yes I set up Can Gow yes, but nothing changes, the subform becomes large (fixed height) regardless of the number of records

I try to link the link again
https://access-programmers.co.uk/forums/showthread.php?t=276977
 
Unfortunately, the link didn't add much...

Can you upload a cut down version of your db with the form / subform & some example data needed to see it in action.
If the data is confidential, change it as necessary

Also please tell me what the 'mask' comment means
 
Yes, in fact, the data is confidential and I do not know how to do it. Is there another way to adjust the height of the subform based on the number of records?
 
What you have already done should work
That's why I said to upload your db

If unsure how to create a stripped down version
1. Create a new empty db
2. Import your form/subform & related tables / queries
3. Check it works - if not add anything else that is needed
4. Remove ALL records.
5. Replace with about 5 'dummy' records which aren't confidential
6. If necessary, zip the file then upload as an attachment

See here for further instructions
https://www.access-programmers.co.uk/forums/faq.php?faq=vb3_reading_posting#faq_vb3_attachments
 
the code you require would be something like

Code:
with me.subformname
    
    .height=.form.section(1).height +  .form.section(2).height+(.form.section(0).height * .form.recordset.recordcount)
 
end with
you may need an adjustment factor for the subform borders and adjust recordcount if you need a 'new' row to add new records

this only works for continuous subforms, if they are datasheet you need a completely different approach based on fontsize

Note: Cangrow only applies when the form is printed

EDIT - missed the recordset from the last bit of code

EDIT2 - added an example
 

Attachments

Last edited:
This is exactly what I was trying to do. Thank you both
 
I realized that, by entering this code for the height of the subforms on the Current event of the main form, sometimes, when I insert a new record in the main form, sometimes I get the error 3021 No current record. If I remove the height code, the error disappears. Can I modify it to tell the mask to "apply" it only when I have entered all the values ​​of the corresponding record?
 
sorry, don't understand the question but suspect it is related to which event runs the code. Also can you confirm what you mean by 'mask'? I thought it was form, but you are using that word as well
 
yes I explained myself badly, the two subforms report the data from two queries. Next to each subform there is a button that allows me to insert values ​​into two tables, from which the data are filtered from the queries and become visible in the two subforms. I realized that sometimes when I insert a new record in the main form (where there are subforms and buttons), if I try to close it I get the error message No current record, even if the record is inserted regularly. I tried to remove the code that adjusts the height of the subforms and the error message no longer appears
 
suspect you need some error control, but without knowing what event is triggering the code and what code you are actually using, I can't tell you what it might be
 

Users who are viewing this thread

Back
Top Bottom