Option Group Choice Hiding Tabs Help

C

cpocpo

Hello.

I have a tblEmployee.

I have an Option Group with 2 Option Buttons. One says "Civilian" and
the other "Military".

What I wanted is when the user selects the "Military" button,
something (a form or enabled combo box) would be enabled and allow
selection of the 1) military branch of service and 2) rank.

If the user selects "Civilian", something would be enabled for the
user to select the civilian paygrade.

As the user toggles the buttons, the forms would toggle also.

I did a 2-Tab control (one for civilian, one for military) , and put a
form on each tab. I am havong trouble with the hide code. Everythign I
try keeps hiding both tabs.

When the button changes state, the forms need to change state also.

I can't get this to work! Any help appreciated!

V/R

LostGuy
 
G

Guest

Hi

You could create some controls on the form that refer to either civilians
and military and then use the afterupdate event of the toggle to make them
visible or not - the control should be set to visible = no OnActivate of
form

Private Sub FrameName_AfterUpdate()
Select Case Me!FrameName
Case 1
Me.MilitaryControl1.Visible = False
Me.MilitaryControl2.Visible = False
Me.MilitaryControl3.Visible = False
Me.CivilianControl1.Visible = True
Me.CivilianControl2.Visible = True
Me.CivilianControl3.Visible = True
Case 2
Me.CivilianControl1.Visible = False
Me.CivilianControl2.Visible = False
Me.CivilianControl3.Visible = False
Me.MilitaryControl1.Visible = True
Me.MilitaryControl2.Visible = True
Me.MilitaryControl3.Visible = True
End Select
End Sub

There are many many way to do this (you could simply create a popup linked
to the primary field, combine the fields into groups, etc etc) but the above
way is really easy and not likely to go wrong.

Hope this helps
 
C

cpocpo

Wayne,

I tried something like that (OgCivorMil is the Option Group with the 2
buttons, cbo's are Combo Buttons, btn's are Buttons going to another
form.)

So selecting "Civilian" shows 1 combo and 1 button and selecting
"military" shows 2 combos and 1 button.

I did some overkill and put it in both the BeforeUpdate and
AfterUpdate Events for the Option Group and the Form, but it is still
buggy .

The problem I am having is this:

1) Open the database and go to the Employee form where that Option
Group is.
2) The first record is a military guy, so when you look at the form,
the military button is clicked and the right combos and buttons are
lit and the wrong ones are grayed out...good
3) When you select the next record (a civilian guy), the button is on
civilian, but his buttons and boxes are gray and the military ones are
lit...bad

What it should be doing when you select a record, the wrong boxes get
grayed out and the right ones get enabled based on the option group
value. What it is doing is whatever combos where enabled in the
previous record are being carried to the next record, regardless of
what position the option buttons are in.

Here's the code:


Private Sub OgCivorMil_BeforeUpdate(Cancel As Integer)
If OgCivorMil.Value = 1 Then
cboCivPayGrade.Enabled = True
cboBranchofService.Enabled = False
cboMilRank.Enabled = False
btnUpdateCivRecReqs.Enabled = True
btnUpdateMilRecReqs.Enabled = False
Else
cboCivPayGrade.Enabled = False
cboBranchofService.Enabled = True
cboMilRank.Enabled = True
btnUpdateCivRecReqs.Enabled = False
btnUpdateMilRecReqs.Enabled = True

End If
End Sub

???

V/R

LostGuy
 
J

John Spencer

You need to add the code to the Current Event of the form also. So that
when you change records the code will run.

Tricky part here is to make sure that you set the focus to some control that
will not be involved in the activity before you start enabling/disabling
controls.

It would be a good idea to write a sub in the form that does all the work.
That way you only have to change the code in one place and call it from the
form's current event, the option group control's after update event, and any
other place that you may need to call it.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
C

cpocpo

John,

CurrentEvent was the place to stick it!

I toggle the buttons and the fields are now enabling and disabling
like crazy (which is how it is supposed to work).

(Now, maybe I can go back and delete it from all the other Events I
had it in.)

Thank you!

V/R
LostGuy (but slowly coming around)
 

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