Using an option group to display a subform

J

Jason

Is it possible to use an option group to display a subform. I am looking to
show subform1 if option one is selected and subform two if option two is
selected. Is this possible? Thanks
 
K

Klatuu

Yes it is. Use the option group's After Update event to make the source
object of the subform control the form you selected.

If Me.MyOptionGroup = 1 Then
Me.MySubformControl.SourceObject = "subform1"
Else
Me.MySubformControl.SourceObject = "subform2"
End If
 
O

Ofer Cohen

In the AfterUpdate event of the Option Group you can write the code

Select Case Me.OptionGroupName
Case 1
Me.[SubFormControlName].SourceObject = "SubForm1"
Case 2
Me.[SubFormControlName].SourceObject = "SubForm2"
End Select

Note: check the option number of each option in the group
 
J

Jason

Dave thanks for the reply

I am a rookie at this can you help me out with the exact language? Here is
what I tried and ended up with errors. Here is the text

Private Sub Frame43_AfterUpdate()
If Me.myoptiongroup = 1 Then
Me.MySubformcontrol.SourceObject = Frm_EmployeeCerts
Else
Me.MySubformcontrol.SourceObject = Frm_EmployeePhone
End If
End Sub
 
K

Klatuu

First, you need to use the actual names of your objects an properties, not
the example names I used. Then, the subform name have to be in quotes.

Use the name of your option group control
v
If Me.myoptiongroup = 1 Then
Use the name of the subfomr control on your form
v
Me.MySubformcontrol.SourceObject = "Frm_EmployeeCerts"
Else
Use the name of the subfomr control on your form
v
Me.MySubformcontrol.SourceObject = "Frm_EmployeePhone"
End If
 
J

Jason

Thank you very much that got it. I guess I spent way too much time relying on
the wizards.
If I want to add more options to the group would I just add another if
statement?

i.e.

Private Sub Frame43_AfterUpdate()
If Me.Frame43 = 1 Then
Me.EmployeeSubformcontrol.SourceObject = "Frm_EmployeePhone"
Else
If Me.Frame43 = 2 Then
Me.EmployeeSubformcontrol.SourceObject = "Frm_EmployeeCerts"
Else
Me.EmployeeSubformcontrol.SourceObject = "the new sub form"
End If
End Sub


Thanks again
 
K

Klatuu

You could, but a better way is to use the Select Case statement once you get
to 3 or more options:

Select Case Me.Frame43
Case 1
Me.EmployeeSubformcontrol.SourceObject = "Frm_EmployeePhone"
Case 2
Me.EmployeeSubformcontrol.SourceObject = "Frm_EmployeeCerts"
Case 3
Me.EmployeeSubformcontrol.SourceObject = "the new sub form"
End Case

Also, as a matter of style, use some indenting. When every line starts at
the left margin, it make the code very difficult to read.
 
J

Jason

Now I am having difficulty limiting the records in the sub form to what is
relavent to the main form. I can do it through the Qry the subfrom is based
on but that seems limiting. Can I add a where clause somewhere that will do
it?

Where Frm_EmployeeCerts.[QI Number] = Frm.EmployeeEditpage.QI
 
C

Charles Wang[MSFT]

Hi Jason,
Yes, you can add the WHERE clause to your query for filtering the records
according to your specific condition. Did you encounter any problem when
you use it?

Best regards,
Charles Wang
Microsoft Online Community Support
=====================================================
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================
 
Top