Results 1 to 8 of 8

Thread: [RESOLVED] Disabling a combobox based on selection in another combo box

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2009
    Posts
    39

    Resolved [RESOLVED] Disabling a combobox based on selection in another combo box

    Hello all,

    I have a form in which I need to disable a combobox based on a selection in another combobox.

    For example, there are 2 comboboxes C1 and C2.

    C1 has a dropdown list with values apple, banana, orange, grapes, kiwi.

    When the user chooses orange from the list in C1, the combo box C2 should automatically be disabled. Can someone tell me how to do this? I am new to VB and I am still learning. Please help ASAP.. Thanks

  2. #2
    Hyperactive Member jp26198926's Avatar
    Join Date
    Sep 2008
    Location
    General Santos City, Philippines
    Posts
    310

    Re: Disabling a combobox based on selection in another combo box

    If Combo1.Text = "orange" Then Combo2.Enabled = False
    "More Heads are Better than One"

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Disabling a combobox based on selection in another combo box

    Code:
    If Combo1.Text = "orange" Then 
          Combo2.Enabled = False
    Else
          Combo1.Enabled = True
    End If
    All too often a control gets disabled, and then winds up staying that way until the form is reloaded (Lord knows I've done that in my apps before ) - Always leave an enabled option available.

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Disabling a combobox based on selection in another combo box

    Quote Originally Posted by Hack View Post
    All too often a control gets disabled, and then winds up staying that way until the form is reloaded (Lord knows I've done that in my apps before ) - Always leave an enabled option available.
    Just another way of doing it.
    Code:
          Combo2.Enabled = (Combo1.Text = "orange")

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Disabling a combobox based on selection in another combo box

    Absolutely correct MarkT. Thanks for pointing that out. Typically, that is the way that I do it in my apps.

    I have discovered over the years, however, that those with less experience find that one liner confusing so I usually post the long way when answering questions like this.

  6. #6
    Addicted Member
    Join Date
    Jan 2007
    Posts
    143

    Re: Disabling a combobox based on selection in another combo box

    Here's another way of doing it:

    Code:
    Private Sub Combo1_Click()
        If Combo1.List(Combo1.ListIndex) = "orange" Then
            Combo2.Enabled = False
        Else
            Combo2.Enabled = True
        End If
    End Sub
    .ListIndex is the item order of the values/entries in your combobox. Starts with 0 onwards

    Using .List together with the .ListIndex works basically the same as using .Text. This code might be useful if you don't know the word you're looking for, but happen to know what item position it is in.

    Just sharing the options.

  7. #7
    New Member
    Join Date
    Apr 2014
    Posts
    1

    Re: Disabling a combobox based on selection in another combo box

    Quote Originally Posted by Hack View Post
    Code:
    If Combo1.Text = "orange" Then 
          Combo2.Enabled = False
    Else
          Combo1.Enabled = True
    End If
    All too often a control gets disabled, and then winds up staying that way until the form is reloaded (Lord knows I've done that in my apps before ) - Always leave an enabled option available.

    I may be going about this all wrong, please be kind if you wish to send me in another direction. I am a bit lost trying to locate the information that I am needing.

    I am using MS Access 2013, and I have tried over and over to use this type of code with NO luck at all in my current database. I have searched and searched several forums, and this was the best info that I could find. The only problem is that it isn't working for me. Is there possibly a "bug" in my version of Access? What info do I need to share for help? It seems like such a simple if statement, but absolutely will not work for me.

    This is what I have in the on current event:

    If IsNull (ContractorCmbo) Then
    ProjMgrCmbo.Enabled = False
    Else
    ProjMgrCmbo.Enabled = True
    End If

    According to the instructional video that I am using to build this particular database, this is supposed to work. I have done exactly what (as far as I can tell) the video shows, but his works on the vidoe and mine does not. After spending what I consider, a lot of money on the video, the company wants to charge even more to help me figure this out. I was hoping I could get help elsewhere.

    I have been stuck on this for a week. Any help would be greatly appreciated...even if it is directing me somewhere else.

    Thanks in advance!!!

  8. #8
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: [RESOLVED] Disabling a combobox based on selection in another combo box

    What exactly are you trying to do?

    Can you post the entire block of code that this snippet resides in?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width