Link to home
Start Free TrialLog in
Avatar of WS
WSFlag for United Arab Emirates

asked on

MS Access - Form - Add color to combo box drop down using Conditional Formatting

Hey,

I have a combo box in a form that have record source as two field i.e ID and Full Name. The width of ID field is set to zero to hide it. I want to color the drop down list as the record having ID from 500 to 508 should have grey back ground in drop down list, and then from 509 to 515 as green and so on, can anyone let me know how to achieve this? I have tries using conditional formatting but it's not working either i am doing something wrong or it's not working, any help?

Thank you.
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

I don't think that this is possible...the only thing you could do is to mimic it by using a small borderless form that you will place it under a fake combo box (the fake combo box should be a text box and command button )...it would take some work...
Avatar of WS

ASKER

I have look on internet and people have achieve this using Conditional Formatting for combo box. In my case i am not sure how to make this working using ID as the field which is visible is Full Name and i want to apply on Full name using ID field. It can be achieve but how to trigger this is basically what i am confused about.
As John said, you can't do this.  The conditional formatting applies to the text box portion of the control, not to the list.

 You would have to use a a sub form in continuous form view along with a text control to mimic the combo control.  in that way, you could do what you want.  You would use the OnChange event of the text control to incrementally search the subform.

Jim.
Avatar of WS

ASKER

does can be done via VBA as i am not able to understand the other way in my case?
The whole concept has to be done in vba...there is no other way...
Avatar of WS

ASKER

I found this somewhere, and as they mention  "Change color of item thats in a combo drop down list"  using:

You can do this with Conditional Formatting, assuming you're running Access 2000 or later. In Design View, select the combobox and goto Formatting - Conditional Formatting and then select

Field Value Is

Equal To

then enter the value that you wish to format on.

Now choose the formatting.

Click OK.

....
Isn't there a way to achieve this using this method in my combo box?
The only "easy" thing you can do(with VBA) is to use an Activex control named ImageCombo so that you have color indicators (images) before your info...just follow the tutorial from MS..
<<Isn't there a way to achieve this using this method in my combo box?>>

 None with the native combo that I am aware of.

Jim.
ASKER CERTIFIED SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is this non-standard functionality a hard requirement?
Or is this something you are just "wondering about"?

As all the Experts above have stated, ...this is not something that Access can easily do.

I will throw out another option.
Since we don't know if the number "ranges" as finite or not, I would add a calculated field to the list with the actual "Name" of the range.
(This would also help so that users do not need a color legend to see what each color means )
Also note that your ranges themselves vary:
500-508=9 Records
509-515= 7 records,
...not sure if this is relevant or not.?
Finally, we don't know if the ranges need to be redefined regularly.


Create a simple public function to define the ranges:

Public Function GetRange(YourID) As String
    If YourID >= 500 And YourID <= 508 Then
        GetRange = "Red"
    ElseIf YourID >= 509 And YourID <= 515 Then
        GetRange = "Green"
    ElseIf YourID >= 516 And YourID <= 530 Then
        GetRange = "Blue"
    ElseIf YourID >= 531 And YourID <= 535 Then
        GetRange = "Yellow"
    End If
End Function

Set the rowsource of the combobox to something like this: (and adjust the column count accordingly):
SELECT tblOrders.OrderID, tblOrders.CustomerName, GetRange([OrderID]) AS Range
FROM tblOrders;

You get something like this:



Sample db is attached.

JeffCoachman
Avatar of WS

ASKER

@Jeffrey,
Is this non-standard functionality a hard requirement?
Or is this something you are just "wondering about"?
It's the requirement of user, as the drop down is a combination of Country and Regions so they want to differentiate the two with colors.

..not sure if this is relevant or not.?
Finally, we don't know if the ranges need to be redefined regularly.
Yes the ranges are not fixed like for first 9 it will be red then for the other seven it will be grey for the next different but i can make them fix like for first 10 red then for next 10 green and so.

@PatHartman, i have Access 2016 and it's 64-bit.
Avatar of WS

ASKER

Also is there any suggestion like to how to meet these user requirement in other way would also be helpful like other than coloring is there a way?
with my solution ...which probably bypassed it...you can even have the flag of the country....:)
Avatar of WS

ASKER

@John, no no it's not bypassed, i am working on that to see will that work in my case because i am a bit confuse in your solution to how much extend it will meet user requirements, do you have any sample db with that , if yes it would be helpful if you share that.
sorry its inside a proprietary application i have build...but the solution is quite easy as long as you follow the tutorial...just drop on the form the control along with an imagelist....store on the imagelist the flags...populate the combobox...
Avatar of WS

ASKER

but this will be image right? not the color on combo box list, am i correct?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Color is not possible in a combo.. It is possible in an ActiveX listbox control.  However, I don't believe any of the old controls have been translated for 64-bit.

Microsoft is still recommending to NOT install 64-bit Office unless you need to support humongous spreadsheets.  there is nothing "better" about 64-bit office and you loose any 32-bit addins that have never been converted.