Switch Microsoft Access Subforms Based on a Combo Box Selection
Question details
Display a different subform in Microsoft Access when a user selects a test from a combo box.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A parent form contains a test selection combo box and should show the form associated with the selected test.
- Observed behavior
- The desired result is for the embedded subform to switch to the appropriate test-specific form whenever the combo box value changes.
Create the test-specific forms and add a subform control and a test-selection combo box to the parent form. Note the control names, form object names, and the combo box's bound values; unique test IDs are preferable to test names.
Change the subform SourceObject in the combo box After Update event
Use this approach to load a different form into the same subform control for each test selection.
The SourceObject property determines which form an embedded subform control displays. The example uses numeric test IDs 1 and 2; replace them with your actual bound values and form names.
In the Access Navigation Pane, right-click the parent form and select Design View. Select the subform control and check its Name on the Property Sheet; this example uses sfrmTests.
Select the test combo box, open its Property Sheet, and choose the Event tab. Set After Update to [Event Procedure], then click the ellipsis button to open the VBA editor.
Inside the combo box's After Update procedure, add the following code, replacing the example control names, IDs, and form names with your own: Select Case Me.cboTestName.Value Case 1 Me.sfrmTests.SourceObject = "Form.frmUrea" Case 2 Me.sfrmTests.SourceObject = "Form.frmOtherTest" Case Else Me.sfrmTests.SourceObject = "" End Select
Save the form, switch to Form View, and select each test in the combo box. Confirm that the matching form appears and that an unmatched or empty selection clears the subform.

Work with exported test data in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with Office documents. Export Access data to Excel to bring it into WPS Spreadsheets; Access forms, VBA events, and subforms do not migrate automatically and must be rebuilt using a suitable tool.

Frequently Asked Questions
Why does changing SourceObject switch the subform?
A subform control displays the form named in its SourceObject property. Assigning another form, such as "Form.frmUrea", replaces the form displayed in that control.
Should the combo box use a test name or a test ID?
A unique test ID is generally more reliable because names can change or be duplicated. Set the combo box's Bound Column to the column containing the ID, and use those IDs in the Select Case statements.
Why does the subform not update when I move to another record?
The combo box's After Update event runs when its value is edited, not when you navigate between records. Use the parent form's Current event to call the same switching procedure.
How do I keep the subform related to the current parent record?
Select the subform control in Design View and check its Link Master Fields and Link Child Fields properties on the Property Sheet. The linked fields must be appropriate for each form loaded into the control.
What happens if no test matches a Case statement?
In the example, Case Else sets SourceObject to an empty string, clearing the subform control. Add more Case statements for additional test IDs and their corresponding forms.




