Enabling multiple commands after a check box

johho0ha

Registered User.
Local time
Today, 06:01
Joined
Apr 9, 2007
Messages
10
I have no clue as to where to start with this. Basically this is what I want to happen. If "Smoker?" = yes (checked), then "smoker status", "# of years smokes", "packs smoked", "years quit" would open up to allow the person entering the data to answer the questions specific to the check box. The fields after "Smoker?" are a combination of list boxes, text boxes, option buttons.

If "smoker?" = no (not checked), then the fields are grayed out and bypassed to the next check box or field not related to "smoker?" and when tabbed, the cursor will skip the gray fields.

Sounds so simple, but yet I have no idea how to approach this. Please help!

Jona
 
Put "smoker" in the tag of each of the controls you want enabled or disabled if the check box is checked/unchecked.

Then, in the after update event of the checkbox put:
Code:
Dim ctl As Control

For Each ctl in Me.Controls
  If ctl.Tag = "smoker" Then
     ctl.Enabled = True
  Else
     ctl.Enabled = False
  End If
Next ctl

Then, be sure to put the same code in the Form's On Current event so it will enable/disable based on the stored selection in the checkbox.
 
I goofed slightly.

In the Checkbox's after update event and the form's on current event:

Code:
 Dim ctl As Control

If Me.YourCheckboxNameHere = True Then
        
  For Each ctl in Me.Controls
    If ctl.Tag = "smoker" Then
     ctl.Enabled = True
    End If
  Next ctl

Else
  For Each ctl in Me.Controls
    If ctl.Tag = "smoker" Then
     ctl.Enabled = False
    End If
  Next ctl
End If
 
Yay! That worked. But now I tried to do the same code for a different tag, "symptom," for another check box in the same form, but that doesn't work. What do I have to do differently?
 
First, you need to put it in the after update event for the checkbox for symptoms. Next, the form's after update event needs to have the same thing put in underneath the other code we put in.
 
Enabling multiple commands based on combo box selection

I'm sure this procedure is similar to what you have given me above, but I don't know what I have to change to apply to the selection of a combo box instead of a check box.

Here is the combo box selections:

T1
T2
T3
T4

based on which particular selection, I'd like to be able to enable the commands that are tagged that particular selection.

thanks
 

Users who are viewing this thread

Back
Top Bottom