Enabling a combo box based on another combo box

peted

Registered User.
Local time
Today, 11:06
Joined
Jan 31, 2008
Messages
18
I have got 3 combo boxes (named SP_combox_box, CP_combo_box and Partial_evol_combo_box) which I only want enabled if another combo box (called PartSz_combo_box) is filled in as “Yes”. I’ve tried two different ways to do this, neither of which works.

The first was to write the following code associated with PartSz_combo_box’s Event procedure:

Private Sub PartialSz_combo_box_AfterUpdate()
If PartialSz_combo_box = "Yes" Then
SP_combo_box.Enabled = True
CP_combo_box.Enabled = True
Partial_evol_combo_box.Enabled = True
Else
SP_combo_box.Enabled = False
CP_combo_box.Enabled = False
Partial_evol_combo_box.Enabled = False

End If

End Sub

The second way I tried was through using conditional formatting. For instance, I clicked on the SP_combox_box and set the conditional formatting so that it read:
Condition 1 Expression Is [PartialSz_combo_box]="No" (and I then clicked on the enable icon).

Neither of these has worked, however. Can anyone set me along the right path?

Thanks
 
Your first code should certainly have worked, assuming you have the names spelled correctly. What exactly do you mean when you say that it didn't work?

SP_combo_box, CP_combo_box and Partial_evol_combo_box need to start out being disabled.

Also, the code needs to be placed in the form's OnCurrent event so that the comboboxes remain enabled or disabled according to the value of PartialSz_combo_box of as you move from one record to another. This is assuming, of course, that PartialSz_combo_box is bound to a field in the underlying table.

Code:
Private Sub Form_Current()

 If Not Me.NewRecord Then
   If PartialSz_combo_box = "Yes" Then
    SP_combo_box.Enabled = True
    CP_combo_box.Enabled = True
    Partial_evol_combo_box.Enabled = True
   Else
    SP_combo_box.Enabled = False
    CP_combo_box.Enabled = False
    Partial_evol_combo_box.Enabled = False
   End If
 Else
   SP_combo_box.Enabled = False
   CP_combo_box.Enabled = False
   Partial_evol_combo_box.Enabled = False
 End If
 
 End Sub
 
Thanks for your reply. I have tried putting that code in the On Current, and it still doesn't work. By which I mean the boxes remain disabled no matter what is entered in the PartialSz_combo_box. Everything is spelled corrrectly,too. I'm not entirely sure what you mean when you say ensuring it is bound to the underlying table, but it does point to a control source named PartialSz. Any more ideas?
 
peted,

You do want your code on the Form_Current event, but unfortunately you
must also use it on the AfterUpdate event of PartialSz_combo_box, so that
it will apply after they change the combo's value.

Wayne
 
Wayne's correct! My reply was, perhaps, poorly worded; by also had to be in the OnCurrent I meant that in addition to to your code in the AfterUpdate event where you already had the code. Perhaps you do have it in both places. At any rate, with the given code in both events, if it still doesn't work, we have to look at other things.

In looking back, you don't state what version of Access you're using, which might help us in trouble shooting this for you.. In v2007, for instance, no code will work unless the location of the database file has been declared as a "Trusted Location."

Comboboxes can also remain disabled if the form itself is read-only or has AllowEdits set to No/False; I assume, from what you've said, that this is not the case, however, since presumably you can select Yes from PartialSz_combo_box.

Let us know the version you're running.
 
Thanks for your replies. Prior to receiving them I decided to start my form all over again. This time it worked (using the conditional formatting method rather than writing code). I didn't appear to be doing anything differently, but presume I must have been. I am using v2007, so it may be that some of the problems you mentioned regarding the code were responsible. I'll bear those in mind for the next form that I do. Thanks again.
 

Users who are viewing this thread

Back
Top Bottom