MS Access: How to Collapse and Expand a Sub-form

Hello everyone,

I am new to Access and designing my first Database. I have multiple sub-forms in my main form. i want, that when one sub-form is expanded the other one gets collapse. so please anyone guide me to get this feature.

Thanks

|

* Please try a lower page number.

* Please enter only numbers.

* Please try a lower page number.

* Please enter only numbers.

I think I would use a tab control, and place each subform on a separate tab.

That way, only one subform will be visible at a time.

---
Kind regards, HansV
https://www.eileenslounge.com

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

For an illustration of the sort of form/subforms interface which Hans describes you might like to take a look at FormsDemo.zip in my public databases folder at:

https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169

Note that if you are using an earlier version of Access you might find that the colour of some form objects such as buttons shows incorrectly and you will need to  amend the form design accordingly.  

If you have difficulty opening the link, copy the link (NB, not the link location) and paste it into your browser's address bar.

This little demo file illustrates a number of possible interfaces, including the use of subform on pages of a tab control.  In this, the principle data from the parent form's recordset is shown in controls above the tab control, so that it is permanently visible.  Secondary data from the parent form's recordset is shown on page 1 of the tab control.  Each of the other pages contains a single subform.

I have occasionally used the sort of setup which your describe, by having a single subform control in the parent form, and changing its SourceObject property by means of an unbound object group in the parent form.
_____________________
Ken Sheridan,
Cannock, England

"Don't write it down until you understand it!" - Richard Feynman

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thanks,

but i don't want to link all sub-forms.

i want that only those sub-forms will appear that are selected by user.

any help...

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thanks,

but i don't want to link all sub-forms.

i want that only those sub-forms will appear that are selected by user.

any help...

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Whether the subforms are linked or not is immaterial.  The methodology is the same; either put each on a separate page of a tab control (recommended), or change the SourceObject property of the subform control in code.
_____________________
Ken Sheridan,
Cannock, England

"Don't write it down until you understand it!" - Richard Feynman

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

I've now added an option to my FormsDemo file, to which I referred your earlier, to open a form in which a subform control's SourceObject property is changed by means of an option group.

In your case, as not all of the subforms are linked, you would also need to change the LinkMasterFields and LinkChildFields properties of the subform control in the option group's AfterUpdate event procedure.
_____________________
Ken Sheridan,
Cannock, England

"Don't write it down until you understand it!" - Richard Feynman

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thanks Ken Sheridan,

but the thing that i want to do is:

user select a sub-form from combo-box and that sub-form appears.

and if user again select another sub-form so that will appear but the first one get close.

i want that if user select another sub-form the first one get collapse.

thanks

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

user select a sub-form from combo-box and that sub-form appears.

You'd do exactly the  same as is done in my demo, but with the code in a combo box's AfterUpdate event procedure rather than an option group's.  Remember that if the value of the combo box is a string expression, rather than a number as with an option group, you must wrap the value in quotes characters in the code.

Note what I said about the need in your case to also change the LinkMasterFields and LinkChildFields properties of the subform control in the code.  If the subform is not linked to the parent form set both to the vbNullString constant.

_____________________
Ken Sheridan,
Cannock, England

"Don't write it down until you understand it!" - Richard Feynman

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

There is an alternative to using a Tab control. While I think a Tab control is an easier interface, you can try changing the Source Object.

A subform control is a special control that is used to display another form, especially one that can be linked to the main form. The name of the other form is used as the SourceObject (a form property) of the Control. So you could change (in VBA code) the SourceObject of your subform control. This would then display the selected form within the subform control.

Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Microsoft Access MVP since 2007

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

....................So you could change (in VBA code) the SourceObject of your subform control. This would then display the selected form within the subform control.

That's exactly what my demo does, but for some reason the OP seems to be having a problem getting their teeth around it.

_____________________
Ken Sheridan,
Cannock, England

"Don't write it down until you understand it!" - Richard Feynman

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

* Please try a lower page number.

* Please enter only numbers.

* Please try a lower page number.

* Please enter only numbers.

 
 

Question Info


Last updated November 28, 2018 Views 2,680 Applies to: