Question

Locked

How to inactivate a combo box based on the choice in another combo box ?

By twitter102010 ·
Hello,

I am working on an access database and I have created a form with three drop down boxes among several others. The first combo box is a called issue type and it has the options exception and re-pick in the drop-down. The second and third combo boxes are titled 'Exception reason' and 'Re-pick reason' respectively.
Now, if I choose exception in the first combo box, I want the 2nd combo box, exception reason, to become active while the third combo box, 'Re-pick reason' stays inactive. If I select re-pick in the first combo box, I want the exception reason combo box to become inactive and the re-pick reason combo box to become active.

I know I need to write a code in VBA but I am not able to get it to work. Can someone kindly give me the right code to make this work.

With Best Regards,
Ram.

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

In the...

by cmiller5400 In reply to How to inactivate a combo ...

In the VB code for the first combo box you will need to set up code in the BeforeUpdate Event.

Use an If...elseif... such as below

If Combo0.Value = "Val 1" Then
Combo2.Enabled = False
Combo4.Enabled = True
ElseIf Combo0.Value = "Val 2" Then
Combo2.Enabled = True
Combo4.Enabled = False
End If

Collapse -

Reponse To Answer

by twitter102010 In reply to In the...

Thanks for the code. I have used the following code in an Afterupdate event and it seems to work fine. However by default the repick_reason combo box is active, i.e. when I open a new form to fill the data the repick_reason combo box is already active.
The way I want it to work is - when I open a new form both repick_reason and exception_reason are inactive and based on whether I select repick or exception in the issue_type combo box the respective combo box needs to become active.
Can you kindly help me figure out how I can make both the combo boxes inactive by default and then become active based on the choice in issue_type combo box.
Private Sub issue_type_afterupdate()
If Me.Issue_type = "exception" Then
Me.Exception_reason.Enabled = True
Me.Repick_reason.Enabled = False
Else
Me.Repick_reason.Enabled = True
Me.Exception_reason.Enabled = False
End If
End Sub

Collapse -

Reponse To Answer

by cmiller5400 In reply to In the...

Well then you will need to disable those combo boxes in the form designer. Right click on the Exception_reason and Repick_reason combo boxes and choose properties and change the "enabled" value to "no" on the "All" tab.

Back to Windows Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums