Link to home
Start Free TrialLog in
Avatar of Jass Saini
Jass Saini

asked on

Subform to show the form according to how many records

Sorry for all the questions...How can you set the subform to show the form if it only has two records and expand if it has twenty records?  Is there a setting for that or do you have to write code..either way please explain
ASKER CERTIFIED SOLUTION
Avatar of Eirman
Eirman
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To me it is not really practical to Hide/show the subform, ...because of the code needed to check for existing records.
Also hiding/showing controls is a confusing interface for users. (They will wonder why sometimes they see the subform and sometimes not...)
There are other reasons as well...
Like the fact that you may have to "unhide" it if you need to add a subform record.
Standard design rules say that you always display the subform, when there are no records, ...it will be empty.

Eirman, has addressed your design and "expand" issues.

;-)

JeffCoachman
Although I generally agree with Jeff's comment:
"Standard design rules say that you always display the subform, when there are no records, ...it will be empty."

I will occasionally violate this rule if the contents of the subform is based on multiple selectable values on the main form.  For example, I frequently use subforms to display datasheets or continuous forms which are based on a query, and are not bound by a parent/child relationship on the main form.  When I do this, I will generally hide the subform when a user changes a selection in one of the controls which define the query results, so that if the user gets distracted and comes back to his computer, he/she does not think that the information displayed in the subform is reflective of the selectable parameters.  In this case, if any of the controls in the main form are changed, I hide the subform until such time as the user clicks the "Update" button on the main form.
Avatar of Jass Saini
Jass Saini

ASKER

Thank you
You can make the form sizable by adding fourlines of code to the main form's resize event.
Private Sub Form_Resize()
    Const LeftRightPadding = (0.125 + 0.25) * 1440
    Const TopBottomPadding = (0.68 + 0.45) * 1440
    
    Me.sfrmFindRejects.Height = Me.InsideHeight - TopBottomPadding
    Me.sfrmFindRejects.Width = Me.InsideWidth - LeftRightPadding
End Sub

Open in new window

You'll have to play with the constants because the values that work will be dependent on the size of the form's header and footer and where on the form the subform is.
User generated imageUser generated image