422,538 Members | 2,084 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,538 IT Pros & Developers. It's quick & easy.

Combobox: disable or grey out items in the list

P: 24
Access 2010, I am trying to disable "Give back" if I select it from the combobox, but is not working now, before it was because I was using a List, but I am using a query now, any help will be appreciate it

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. If Me.LeavingGroupProfile.RowSource = "SELECT tbl_LeavingGroupProfile.LeavingGroupID, tbl_LeavingGroupProfile.LeavingGroupName " & _
  4.         "FROM tbl_LeavingGroupProfile " & _
  5.         "WHERE (((tbl_LeavingGroupProfile.LeavingGroupName) = 'Give Back' " & _
  6.         "ORDER BY tbl_LeavingGroupProfile.LeavingGroupName; " Then
  7.        Me.Reason_for_Leaving.Enabled = False
  8.     Else
  9.        Me.Reason_for_Leaving.Enabled = True
  10.     End If
  11.  
  12.  
Feb 7 '18 #1

✓ answered by twinnyfo

See Post #2 above.

A streamlined version is below:

Expand|Select|Wrap|Line Numbers
  1. Private Sub LeavingGroupProfile_AfterUpdate()
  2.  
  3.     Me.Reason_for_Leaving.Enabled = Not (Me.LeavingGroupProfile.Value = "Give Back")
  4.  
  5. End Sub
Again, unless we are missing something, this is as straightforward as can be. Please clarify.

Share this Question
Share on Google+
10 Replies


gnawoncents
100+
P: 212
ivonsurf,

I'm a little bit fuzzy on when you're trying to make the disable/enable happen and which object you are trying to do it to. Your code indicates Reason_for_Leaving is the field you want disabled/enabled, so I'm operating off that assumption. If you simply want to disable the field when a user selects "Give Back" from the combo box, the code below should do what you need. If, however, you are trying to have it disable when "Give Back" is even an option to select, that would be another matter.

Expand|Select|Wrap|Line Numbers
  1. Private Sub LeavingGroupProfile_AfterUpdate()
  2.  
  3. If Me.LeavingGroupProfile.Value = "Give Back" Then
  4.     Me.Reason_for_Leaving.Enabled = False
  5.   Else
  6.     Me.Reason_for_Leaving.Enabled = True
  7. End If
  8.  
  9. End Sub
  10.  
Feb 8 '18 #2

P: 24
Hello,

That's the thing it does not work, before worked because the Give back was withing a list of options as a List in that combobox, but now is not longer a list, it is a source: query/Table, when I select Give back it does not go gray out anymore.
Feb 8 '18 #3

twinnyfo
Expert Mod 100+
P: 2,238
ivonsurf123,

Like gnawoncents, I, too, am a bit confused as to what it is that you are trying to disable. If your code sets the Row Source based on a selection from a Combo Box, then there is really no reason to check the value of the Row Source--simply refer to the Combo Box itself, as recommended.

Are we missing some important details about what you are trying to do and how you are trying to do it?
Feb 8 '18 #4

P: 24
I create a table call LeavingGroupProfile, I have a form named Position Fills, in that form I have a combo box with a items to select, one of them is "Give back", now the way I bring that list into the combo box is through a Table/Query Row Source type, what I want to do now is in that combo box from the Position fill form, every time that I select "Give Back" another combobox named Reason for Leaving, also with a list coming from a Table/Query Row source Type to go gray out as soon as I select "Give Back" from Leaving Group Combobox in the Position Fills form.
Feb 8 '18 #5

twinnyfo
Expert Mod 100+
P: 2,238
See Post #2 above.

A streamlined version is below:

Expand|Select|Wrap|Line Numbers
  1. Private Sub LeavingGroupProfile_AfterUpdate()
  2.  
  3.     Me.Reason_for_Leaving.Enabled = Not (Me.LeavingGroupProfile.Value = "Give Back")
  4.  
  5. End Sub
Again, unless we are missing something, this is as straightforward as can be. Please clarify.
Feb 8 '18 #6

P: 24
Thank you twinnyfo, It works perfectly!
Feb 8 '18 #7

PhilOfWalton
Expert 100+
P: 1,085
To the best of my knowledge it is not possible to simply create a coloured row Combo Box, but I vaguely remember downloading a sample DB some years ago. I will see if I can find it when I get onto my main computer tomorrow.

Phil
Feb 8 '18 #8

twinnyfo
Expert Mod 100+
P: 2,238
Technically, speaking, Phil's initial response should be set to "Best Answer." I merely clarified/streamlined his response.

Phil, concerning the colored row combo box, I wonder if it is possible to create a subform that mimics a combo box? But, so as not to hijack this post, that would be another thread/article....
Feb 8 '18 #9

gnawoncents
100+
P: 212
twinnyfo,

Thanks for posting the streamlined example. I've never considered constructing a line that way, but it is cleaner and makes perfect sense. Good stuff!
Feb 8 '18 #10

twinnyfo
Expert Mod 100+
P: 2,238
gnawoncents,

I can't take any credit for that one. It's a little trick taught me by NeoPa. Since I've learned it, it has been incredibly useful in countless ways.

So glad I could hepp!
Feb 8 '18 #11

Post your reply

Sign in to post your reply or Sign up for a free account.