shrink and expand subform

Mike Hughes

Registered User.
Local time
Today, 20:23
Joined
Mar 23, 2002
Messages
493
Is there some way to have this subform shrink or expand in width and height when it is opened.

The number of members for each case is different for each case I seem to always end up with the dark gray space at the bottom of the subform. I would like to have only the members for each case show without the grey. So the sub form would shrink and expand based on the numbers of members on the case. And also shrink and expand in width based on the length of the names of the members? See attached screen shots

Thanks Mike
 

Attachments

  • subform shrink in fit 1.jpg
    subform shrink in fit 1.jpg
    79.4 KB · Views: 1,150
  • subform shrink in fit 2.jpg
    subform shrink in fit 2.jpg
    72.5 KB · Views: 910
Have you tried setting the Subform to display as a continuous form rather than a data sheet?
 
If you are using the Datasheet view for you subform, you could control the widths of each column using ColumnWidth in you VBA code for Form_Current.

Code:
Me.[subformname].Form![ControlOnSubform].ColumnWidth = X

You could work out what X is based on the width of your subform control on the parent form, or use some arbitary percentages of the total width, for example, with your subform control is 7000 wide, then you might allocate FN and LN 20% each.

As for the height, I think the only way to control this is to adjust the actual height of the subform control, possibly using the number of records returned to calculate the approximate height.

Code:
Me.[subformname].Height = Y

Not really an exact science, but you may be able to tweak it to get a reasonable result.
 
You can add code to the Resize event of the MAIN form that will resize a subform in datasheet view:

Const LeftRightPadding = (0.15) * 1440
Const TopBottomPadding = (0.65) * 1440

Me.sfrmMemberList.Height = Me.InsideHeight - TopBottomPadding
Me.sfrmMemberList.Width = Me.InsideWidth - LeftRightPadding

Don't forget to change the subform name to your own form name. You may need to adjust the padding value to get the desired results
 
This works better. I have a subform that does not show when the main form is opened until there are records to populate the subform.

This is what I have in my cmdGo (which is the name of my Go button)
after I have checked to see if there will be any records returned from the value I put in an Unbound checkbox (entrybox) which gets run in the query that is attached to the subform. Set Max Height so your form doesn't go outside the parameters of your main form and deny functionality.

HeightMultiplier = 360
MaxHeight = 9000

NumRecs = DCount("[fieldname]", "tablename", "[field] = Forms![mainForm].[entrybox].value")

ckHeight = HeightMultiplier * (NumRecs + 1)

If ckHeight <= MaxHeight Then
Me.frmEmplDatasub.Height = HeightMultiplier * (NumRecs + 1)
Else
Me.frmEmplDatasub.Height = MaxHeight
End If

It leaves a small amount of space below the last record. I found setting HeighMultiplier to 300 worked better for me.

I don't want the width adjusted, just the height.

I have my subform set as Continuous Forms
 
Last edited:

Users who are viewing this thread

Back
Top Bottom