Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VBA Enable Disable ComboBox

Posted on 2006-03-30
8
Medium Priority
?
13,053 Views
Last Modified: 2013-12-25
I would like to enable and disable ComboBox selection in my Excel workbook.  

There are three ComboBoxes.  The user will make a choice of two items in an initial ComboBox.  If item A is selected then ComboBox A is enabled and ComboBox B is disabled.  If item B is selected then ComboBox B is enabled and ComboBox A is disabled.

Is there code such as:

ComboBox.Enabled = true

I want the initial ComboBox to fire a macro to enable and disable ComboBoxes A and B.
0
Comment
Question by:owntor
  • 5
  • 2
8 Comments
 
LVL 15

Expert Comment

by:Computron
ID: 16338299
In the click event of the combobox, place the code to enable or disable the other 2 combo boxes just like you have above.

If ComboBox = SomeValue Then
  ComboBox1.Enabled = True
  ComboBox2.Enabled = False
Else
  ComboBox1.Enabled = False
  ComboBox2.Enabled = True
End if


There is also a visible property
ComboBox1.Visible = False
0
 
LVL 55

Expert Comment

by:Ryan Chong
ID: 16341136
also can write like this:

combobox1.enabled = (ItemA = someValue)
combobox2.enabled = not combobox1.enabled
0
 
LVL 1

Author Comment

by:owntor
ID: 16342389
Will have to find the click event...  should it be some thing like this?

Private Sub ButtonClickEvent_Click(ByVal Ctrl As Office.CommandBarButton, _
   
    Set ButtonClickEvent = btn
    If Not btn Is Nothing Then
        MsgBox "Synced '" & btn.Caption & "' button events."
    End If
   
End Sub

and I'll rework in the combobox.enabled line into that sort of subroutine...

I will try it this morning.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Accepted Solution

by:
Computron earned 1400 total points
ID: 16342471
Private Sub ComboBox1_Click()
If ComboBox = "SomeValue" Then
  ComboBox1.Enabled = True
  ComboBox2.Enabled = False
Else
  ComboBox1.Enabled = False
  ComboBox2.Enabled = True
End if
End Sub

If you double click the combobox, it should take you to the code view, then switch from change event to click event
0
 
LVL 1

Author Comment

by:owntor
ID: 16343472
Would this only work for the controls ComboBox?  Just to clarify, I am using the forms ComboBox.
0
 
LVL 1

Author Comment

by:owntor
ID: 16344217
I would also like to gray-out the inactive comboboxes.
0
 
LVL 1

Author Comment

by:owntor
ID: 16344691
When I apply this code to the forms comboboxes this error is thrown:  "Object Required."

So I tested this on a couple control comboboxes and it seems to work.

Will test some more...  Still trying to make this work with forms comboboxes...
0
 
LVL 1

Author Comment

by:owntor
ID: 16344867
Aha!  When I populated the comboboxes with data and the macro runs properly.

Thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question