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

Combobox: disable or grey out items in the list

P: 6
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.  
2 Weeks Ago #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: 205
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.  
2 Weeks Ago #2

P: 6
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.
2 Weeks Ago #3

twinnyfo
Expert Mod 100+
P: 1,968
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?
2 Weeks Ago #4

P: 6
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.
2 Weeks Ago #5

twinnyfo
Expert Mod 100+
P: 1,968
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.
2 Weeks Ago #6

P: 6
Thank you twinnyfo, It works perfectly!
2 Weeks Ago #7

PhilOfWalton
Expert 100+
P: 1,042
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
2 Weeks Ago #8

twinnyfo
Expert Mod 100+
P: 1,968
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....
2 Weeks Ago #9

gnawoncents
100+
P: 205
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!
2 Weeks Ago #10

twinnyfo
Expert Mod 100+
P: 1,968
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!
2 Weeks Ago #11

Post your reply

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