Toggle between forms using Option Group in Access Database Forms

G

Guest

Does anyone know how to toggle between a form and a subform using the Option
Group. I have a form, wherein when you select the option button "A" it
enables a control source on the subform to become active, and if you select
the other option "B" button a control source on the main form becomes active
and "A" becomes inactive. Thanks!

James
 
M

Marshall Barton

Please said:
Does anyone know how to toggle between a form and a subform using the Option
Group. I have a form, wherein when you select the option button "A" it
enables a control source on the subform to become active, and if you select
the other option "B" button a control source on the main form becomes active
and "A" becomes inactive.


I'm not sure what you mean by "enables a control source on
the subform to become active". If you mean you want to
enable/disable the controls, then use the option group's
AfterUpdate event procedure:

Me.subform.Form.somecontrol.Enabled = (Me.optAorB = 1)
Me.acontrol.Enabled = (Me.optAorB = 2)

where 1 is the OptionValue of the A option and 2 for option
B. Besure to replace all the made up names with the ones
you are actually using.
 
M

Marshall Barton

That would change my image of the question, but it still
wouldn't make much sense. "making a record source active"
implies that you want to bind a form to a table/query, which
is normally done at design time, not by selecting an option
button on a form at run time.

Could you explain what you are trying to accomplish (not how
you have tried doing it) in more detail without using either
record or control source terminology?
 
G

Guest

Marshall, this is what I am trying to do, I have a form (me.form1) which has
has
an option goup (Option 138), if the user selects "A" in the option group then
the text box in the subform (me.form2)will become unlocked...(the defalt is
locked).
However, if the user selects "B" the text box on the form (me.form1) becomes
unlocked....again the default is locked. I hope this makes sense. I really
appreciate your help.


Marshall Barton said:
That would change my image of the question, but it still
wouldn't make much sense. "making a record source active"
implies that you want to bind a form to a table/query, which
is normally done at design time, not by selecting an option
button on a form at run time.

Could you explain what you are trying to accomplish (not how
you have tried doing it) in more detail without using either
record or control source terminology?
--
Marsh
MVP [MS Access]

Marshall, does it matter if it is a record source instead of a control source?
 
M

Marshall Barton

The Locked property is managed the same way as the Enabled
property. I think you want to use code like this in the
option group's AfterUpdate event procedure:

Me.form2.Form.subtextbox.Locked = (Me.Option138 = 1)
Me.maintextbox.Locked = (Me.Option138 = 2)

You didn't say what should happen when a user navigates the
main form to a different record. Depends on if you want to
lock both text boxes or if the option group is bound and you
want them lock/unlocked as they were the last time the
record was saved.
 
G

Guest

Marshall, it seems that the code for the main form worked, however I keep
getting that debug error on the Me.form2.Form.subtextbox.Locked =
(Me.Option138 = 1), and I don't know why. any suggestions?

Marshall Barton said:
The Locked property is managed the same way as the Enabled
property. I think you want to use code like this in the
option group's AfterUpdate event procedure:

Me.form2.Form.subtextbox.Locked = (Me.Option138 = 1)
Me.maintextbox.Locked = (Me.Option138 = 2)

You didn't say what should happen when a user navigates the
main form to a different record. Depends on if you want to
lock both text boxes or if the option group is bound and you
want them lock/unlocked as they were the last time the
record was saved.
--
Marsh
MVP [MS Access]

Marshall, this is what I am trying to do, I have a form (me.form1) which has
has
an option goup (Option 138), if the user selects "A" in the option group then
the text box in the subform (me.form2)will become unlocked...(the defalt is
locked).
However, if the user selects "B" the text box on the form (me.form1) becomes
unlocked....again the default is locked. I hope this makes sense. I really
appreciate your help.
 
M

Marshall Barton

Which error did you get?

Most likely there's a name error in there somwhere. Check
the name of the text box and especially the name of the
subform control (might be different from the name of the
form object it displays).
 
G

Guest

I checked all of the names and you hit it right on the head, it was a name
issue, this is how it should have looked, it needed the brackets:

Me.catsub100.Form.[Rep Code].Enabled = True

Marshall, thank you for your patience, your help..but most of all for your
generosity of your time and of your knowledge.

Marshall Barton said:
Which error did you get?

Most likely there's a name error in there somwhere. Check
the name of the text box and especially the name of the
subform control (might be different from the name of the
form object it displays).
--
Marsh
MVP [MS Access]

Marshall, it seems that the code for the main form worked, however I keep
getting that debug error on the Me.form2.Form.subtextbox.Locked =
(Me.Option138 = 1), and I don't know why. any suggestions?
 
M

Marshall Barton

Glad I was able to get you pointed in the right direction
and thank you for your gracious thank you.
--
Marsh
MVP [MS Access]

I checked all of the names and you hit it right on the head, it was a name
issue, this is how it should have looked, it needed the brackets:

Me.catsub100.Form.[Rep Code].Enabled = True

Marshall, thank you for your patience, your help..but most of all for your
generosity of your time and of your knowledge.

Marshall Barton said:
Which error did you get?

Most likely there's a name error in there somwhere. Check
the name of the text box and especially the name of the
subform control (might be different from the name of the
form object it displays).
 

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