Using Option Group to Select Sub Form

J

jfullingim

I have a form with 3 subforms and I want to use an option group to select
which subform is visible. Option1 = only Subform1 is visible. Option2 =
only Subform2 is visible. Option3 = only Subform3 is visible. This seems
like it should be fairly simple, but I can't seem to get it to work. Any
help would be greatly appreciated!

Thanks!
 
J

Jack Leach

In the OnChange event of the option group control (not the options
themselves), use this code, assuming the values tied to your option group are
1, 2 and 3


Private Sub OptionFrame_Change()
Select Case OptionFrame
Case 1
Me.SubformControl1.Visible = True
Me.SubformControl2.Visible = False
Me.SubformControl3.Visible = False
Case 2
Me.SubformControl1.Visible = False
Me.SubformControl2.Visible = True
Me.SubformControl3.Visible = False
Case 3
Me.SubformControl1.Visible = False
Me.SubformControl2.Visible = False
Me.SubofmrControl3.Visible = True
End Select
End Sub



Note that SubformControl is the name of the Control that holds the subform,
not the name of the form itself. It's best to make these different (I
generally prefix "ctl" to the name of the control). I haven't tested this
but I believe it should work. You can probably use the AfterUpdate event of
the option group control rather than the Change control, if you like.


hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
J

jfullingim

OK. This stopped me from getting error messages, but doesn't work otherwise.
I think the problem could be in that I haven't used option groups before and
I don't know what the "option group control" is. In the properties of my
option group, there is a field called "control source" that is blank. Should
this option group be attached to some control?
 
J

Jack Leach

Should
this option group be attached to some control?

No, the option group itself is a control, which can be connected to a Field
of the form, but does not need to be.

The Option Group Control (or Frame its called) is the control that's on the
form... the part that is the surrounding box to the options that you can
choose from. Put this in the AfterUpdate event of the option group control
(properties, events, afterupdate, build code...)

The control source is the field (from the form's recordsource) that the
value is stored in... if you don't need to save the value, leave this
blank... it's then referred to as an "unbound" control.

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 

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