Reputation: 1168
I want to create a popup form that contains a list of dynamically created subforms. The number of subforms is determined by the user in the parent form.
Here is a sketch to illustrate what I want to do. The user can change the value of "Num Branches" to be between 2 and 10. This number is in turn reflected in the number of subforms created in the scrollable box below. The subforms are all from the same and I outlined them in red. I have a few questions about how to do this
Upvotes: 0
Views: 955
Reputation: 32632
You probably don't want to dynamically create the subform controls (since creating controls = switching to design view, requires an exclusive lock on the database, etc.)
You can't use something like a continuous form with multiple instances of the subform, since Access doesn't allow subform controls on continuous forms.
My approach would be to have 10 (your max) subform controls on the form, hide them all, and dynamically assign them to specific source objects.
Pseudocode:
Dim numBranches As Long
Dim i As Long
For i = 1 to numBranches
Me.Controls("subform" & i).Visible = True
Me.Controls("subform" & i).Form.Filter = "branch = " & i 'Appropriate filter here
Me.Controls("subform" & i).Form.FilterOn = True
Next i
Upvotes: 2