|
-
Oct 5th, 2009, 08:51 AM
#1
Thread Starter
Member
[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
-
Oct 5th, 2009, 09:02 AM
#2
-
Oct 5th, 2009, 11:18 AM
#3
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.
-
Oct 5th, 2009, 12:15 PM
#4
Re: Disabling a combobox based on selection in another combo box
 Originally Posted by Hack
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")
-
Oct 5th, 2009, 12:47 PM
#5
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.
-
Oct 6th, 2009, 05:49 PM
#6
Addicted Member
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.
-
Apr 7th, 2014, 05:07 PM
#7
New Member
Re: Disabling a combobox based on selection in another combo box
 Originally Posted by Hack
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!!!
-
Apr 8th, 2014, 12:24 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|