Load Subform

B

Bryan Hughes

Hello,

I have a Option Group on a Page Ctl inside of a main form. What I would
like to do is depending on the selection of the option group, load a subform
in a unbound subform on this Page Ctl. How can I do this?

Here is the code I have been trying to use:

Private Sub ctlCPPS_Click()
Select Case Me!ctlCPPS
Case 1
Me!subCPPreSch.SourceObject = Forms!subfrmCare_Provider
Case 2
Me!subCPPreSch.SourceObject = Me!subfrmPreschool
Case 3
Me!subCPPreSch.SourceObject = Me!subfrmSchool
End Select
Me!subCPPreSch.Visible = True
End Sub

Please Help!
 
B

Bob Noll

When I need to do this kind of thing I create three
subforms on my form. Each one already contains the one
of the three forms I want to use. I then make the one I
want visible when required as in:

Dim cur As Integer

Private Sub ctlCPPS_Click()
If cur <> 0 Then
Me.Controls("subform_" & cur).Visible = False
End If
cur = Me!ctlCPPS
Me.Controls("subform_" & cur).Visible = true
End Sub

Hope that helps.
 
S

Steve Conway

Hi Bryan,

You need to pass the name of the form you are using as the SourceObject, as
a string. I am guessing the correct names of the desired forms should
possibily be as below?

Private Sub ctlCPPS_Click()
Select Case Me!ctlCPPS
Case 1
Me!subCPPreSch.SourceObject = "subfrmCare_Provider"
Case 2
Me!subCPPreSch.SourceObject = "subfrmPreschool"
Case 3
Me!subCPPreSch.SourceObject = "subfrmSchool"
End Select
Me!subCPPreSch.Visible = True
End Sub

HTH
Steve C
 
S

Steve Conway

Hi Bob,

The down-side to this method (which may not be an issue for you) is all the
subs are loaded on the main form's open. I have found the set SourceObject
to be faster during startup and much easier to deal with during design. Just
an opinion.

Steve C
 
B

Bob Noll

Steve,

I agree with you, however in my case the user can "flip"
back and forth between "views" and I did not want to be
reloading data each time.

Bob
 
S

Steve Conway

Hi Bob,

Indeed, a very sound reason to use the multiple subform controls method. I
have done the same, for the same reason. As with everything, the best method
is determined by the needs.

Steve C
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top