Reputation: 25
I have a parent form with a tab control. The tabs show subforms. Data shown in the parent form is general details about residential property, such as address, etc. In the tabs, the subforms show data that is county-specific and exhaustive, like garage square footage and on and on.
There are 6 tabs with a static subform i.e. that tab always shows the same subform. I'd like the 7th tab to dynamically open a subform depending on which county the property exists in. That is, based on the value of a control (Me.Form.County
), populate this 7th tab with the corresponding subform for the highly specific details for that county.
(No, it's not desirable to make one subform that could render data for any county; it'd be huge, relatively. One form per county is the requirement.)
It'd be nice if there's a way to act on the event of clicking on the 7th tab to then open the county-specific subform, though I don't see OnClick
for a tab. If there's a way that's close to that simple for the user that'd be fine too.
Upvotes: 0
Views: 311
Reputation: 165
You can use the Subform.SourceObject property to change which form is displayed in a Subform control. https://learn.microsoft.com/en-us/office/vba/api/access.subform.sourceobject
You can use the Change event of the Tab Control to respond to the user switching tabs and display the correct subform if they are looking at the desired tab.
Private Sub tabCounty_Change()
If tabCounty.Pages(tabCounty.Value).Caption = "County Info" Then
subCountyInfo.SourceObject = "frmCounty" & Me.Form.County
End If
subCountyInfo.Form.Requery
End Sub
Upvotes: 3