autogrow subreport on a main report or form (1 Viewer)

scopes456

Registered User.
Local time
Today, 15:50
Joined
Feb 13, 2013
Messages
89
I been searching online but no luck so far. I have a subreport on a main form. I would like the subreport to grow to show all the items when the main form is open. I try using cangrow but no luck. I tried also using a subform , but also no luck. I would like the subreport to grow , so it shows all data without use of the scroll bar.

there was one code I used for the subreport to take up the whole "detail" section of the form, but that was covering other reports.


Many Thanks
 

sneuberg

AWF VIP
Local time
Today, 12:50
Joined
Oct 17, 2014
Messages
3,506
I don't know what you mean by a subreport in a form, but you can adjust the height of a subform dynamically when the form is opened. In the attach database I have the follow code in the form open event of the Main Form

Code:
Private Sub Form_Open(Cancel As Integer)

Dim MaxHeight As Long
Dim ctrl As Control
Dim RecordCount As Long
Dim rst As Object
Set rst = Me.TestData_Form.Form.RecordsetClone
On Error Resume Next
rst.MoveLast
On Error GoTo 0
RecordCount = rst.RecordCount

For Each ctrl In Me.TestData_Form.Form
    If MaxHeight < ctrl.Height + ctrl.Top Then
        MaxHeight = ctrl.Height + ctrl.Top
    End If
Next ctrl
Me.TestData_Form.Height = MaxHeight * (RecordCount + 1)


End Sub

What this does is attempt to calculate the what the height of the subform should be given the position and height of the controls and then multiples that by the record count + 1. I'm not sure why the one is needed and you might want to increase it to two so the new record is shown.

Your situation is probably different but maybe this will get you started.
 

Attachments

  • GrowingSubform.accdb
    416 KB · Views: 116

scopes456

Registered User.
Local time
Today, 15:50
Joined
Feb 13, 2013
Messages
89
sneuberg thank you. This is what I was looking for. I am just wondering, see how you have TestData Form on the main form, and when the main form opens , TestData Form goes to a height to see all records, What if I have another form right under it, would there be any code to "push" that form down so it can be displayed, instead of being covered by the first subform.
 

sneuberg

AWF VIP
Local time
Today, 12:50
Joined
Oct 17, 2014
Messages
3,506
In the attached database I made a copy of the form TestData Form and named it TestData Form2. I added this to the Main Form as another subform. To push this down I added the following line to the form open.


Code:
Me.TestData_Form2.Top = Me.TestData_Form.Top + Me.TestData_Form.Height + 1440

I don't see any limits to how you can position this stuff. Just figure out where you want it, do some calculations and put it there by set the position properties Top and Left
 

Attachments

  • GrowingSubform.accdb
    600 KB · Views: 109

sneuberg

AWF VIP
Local time
Today, 12:50
Joined
Oct 17, 2014
Messages
3,506
Oh and in case you didn't know the values of these properties are in twips. 1440 twips to an inch.
 

bob fitz

AWF VIP
Local time
Today, 19:50
Joined
May 23, 2011
Messages
4,717
Surely it would be much easier for OP to use a tab control for the forms.:confused:
 

Faoineag

Registered User.
Local time
Today, 12:50
Joined
Jan 7, 2018
Messages
40
If in the mask I have two subforms whose height I want to adjust, how does the code become? Thank you
 

Users who are viewing this thread

Top Bottom