Chameleon subform

knauftj

New Member
Joined
Jun 14, 2005
Messages
27
I was wondering if it is possible to have the available fields in a subform change based on a combobox in the parent form? I have a form that has a combobox and I would like the fields available in the subform to change based on what is selected in the combobox. Thanks.

Jon
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Yes, but how you approach it can vary.

Probably the simplest way is to set up a series of tabs on the subform, with sets of fields on each tab. Then, instead of looping through every control (and having to update the code whenever you add a control to the form), you merely hide and display tabs and provide the users with the set of controls that you have placed on that tab. This works well if you have the subform displayed as a form, not in datasheet format.

If you're using datasheet-style subforms, consider placing multiple subforms on top of each other and toggling their visibility.

Whichever route you use, grouping the controls and then hiding or showing the groups is much easier to manage.

Generically, you do it by using the AfterUpdate event of the combo --

Code:
Private Sub MyCombo_AfterUpdate()
  Select Case MyCombo
    Case "Alpha"
      FirstSubForm.Form.Visible=True
      SecondSubForm.Form.Visible=False
    Case Else
    '... etc
  End Select
End Sub

The above is for a subform. To use for a tab, change FirstSubForm.Form to FirstPage, etc

Change names to suit your setup

Denis
 
Upvote 0
Re:

Thanks Denis. I was thinking of using the Visible control but wasn't sure of the code for subforms. Thanks again.

Jon
 
Upvote 0

Forum statistics

Threads
1,203,046
Messages
6,053,192
Members
444,644
Latest member
keepontruckinc4

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top