473,465 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Conditional formatting on a combo box

2 New Member
Working in Access 2007 on XP

I have a combo box that I'm using in a form to select the WorkCategory assigned to a particular person in my database. WorkCategory is a lookup field in a table called Person. It is looking up the category type from another table called WorkCategory which is a list of 3 types of categories (offshore, onshore, visitor).

In the form, when I use the drop-down menu of the combo box to select one of the work categories, I want to have a different background colour for each.

I've been using conditional formatting on the combo box but cannot get it to work?

Tried the following:-

Condition 1: Field Value Is equal to "Offshore"
Condition 2: Field Value Is equal to "Onshore"
Condition 3: Field Value Is equal to "Visitor"

and

Condition 1: Expression Is [WorkCategory]="Offshore"
Condition 2: Expression Is [WorkCategory]="Onshore"
Condition 3: Expression Is [WorkCategory]="Visitor"

and

Condition 1: Expression Is WorkCategory="Offshore"
Condition 2: Expression Is WorkCategory="Onshore"
Condition 3: Expression Is WorkCategory="Visitor"

Hope someone can help. Thanks
Mar 13 '08 #1
3 7019
Lysander
344 Recognized Expert Contributor
Working in Access 2007 on XP

I have a combo box that I'm using in a form to select the WorkCategory assigned to a particular person in my database. WorkCategory is a lookup field in a table called Person. It is looking up the category type from another table called WorkCategory which is a list of 3 types of categories (offshore, onshore, visitor).

In the form, when I use the drop-down menu of the combo box to select one of the work categories, I want to have a different background colour for each.

I've been using conditional formatting on the combo box but cannot get it to work?

Tried the following:-

Condition 1: Field Value Is equal to "Offshore"
Condition 2: Field Value Is equal to "Onshore"
Condition 3: Field Value Is equal to "Visitor"

and

Condition 1: Expression Is [WorkCategory]="Offshore"
Condition 2: Expression Is [WorkCategory]="Onshore"
Condition 3: Expression Is [WorkCategory]="Visitor"

and

Condition 1: Expression Is WorkCategory="Offshore"
Condition 2: Expression Is WorkCategory="Onshore"
Condition 3: Expression Is WorkCategory="Visitor"

Hope someone can help. Thanks
You could be asking for two things, and I am not sure what one it is.

If you want to set the colour of the combo box, after you have selected the option, then use the after_update event and set the colour depending upon the value.
e.g.
if cboWorkCategory="Offshore" then cboWorkCategory.BackColor=-2147483633

If you want to display the list of 3 options, with 3 different colours at the same time, I don't think you can do this easily. You could use an option group of the 3 values, so 3 different buttons with 3 different colours.
Mar 13 '08 #2
aeon
2 New Member
Thanks for your help...I tried using if statements but this did not work. I've also tried a select case as below...this has not worked either.
Expand|Select|Wrap|Line Numbers
  1. Private Sub WorkCategory_AfterUpdate()
  2.  
  3. Select Case Me.WorkCategory & ""
  4. Case "Offshore"
  5.     Me.WorkCategory.BackColor = vbBlue
  6. Case "Onshore"
  7.     Me.WorkCategory.BackColor = vbGreen
  8. Case "Visitor"
  9.     Me.WorkCategory.BackColor = vbRed
  10. End Select
  11.  
  12. End Sub
Mar 13 '08 #3
Lysander
344 Recognized Expert Contributor
Thanks for your help...I tried using if statements but this did not work. I've also tried a select case as below...this has not worked either.

Private Sub WorkCategory_AfterUpdate()

Select Case Me.WorkCategory & ""
Case "Offshore"
Me.WorkCategory.BackColor = vbBlue
Case "Onshore"
Me.WorkCategory.BackColor = vbGreen
Case "Visitor"
Me.WorkCategory.BackColor = vbRed
End Select

End Sub
I have just knocked up a short test on one of my forms, and this works
Expand|Select|Wrap|Line Numbers
  1. Private Sub Mandal_ID_AfterUpdate()
  2. If Mandal_ID = 1 Then
  3.     Mandal_ID.BackColor = vbBlue
  4. Else
  5.     Mandal_ID.BackColor = -2147483643
  6. End If
  7. End Sub
  8.  
Try adding the following to your code, to see if you actually getting the correct value, as I made that mistake, testing for Mandal Name, when the box actually held Mandal ID

Expand|Select|Wrap|Line Numbers
  1. Select Case Me.WorkCategory & ""
  2. Case "Offshore"
  3.     msgbox "TEST, I HAVE GOT HERE"
  4.     Me.WorkCategory.BackColor = vbBlue
  5. Case "Onshore"
  6.     Me.WorkCategory.BackColor = vbGreen
  7. Case "Visitor"
  8.     Me.WorkCategory.BackColor = vbRed
  9. End Select
  10.  
Mar 14 '08 #4

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

Similar topics

3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
2
by: Terry | last post by:
I have a form which displays data from both the Student Details table and the Exam Details table. The Name (Text Box) control is from the Student Details table and the Withdrawn (Check Box)...
2
by: jeffgeorge | last post by:
Trying to add 3 colors to 6 combinations of text possibilities. If this makes sense, the possibilities are: A D (one color for the combo beginning with A) A E B D (One color for the combo...
2
by: Megan | last post by:
Can you write conditional VBA code that affects only one or two records on a continuous subform? I have a form with a subform on it. The parent/ child field that links the forms is CaseID. The...
8
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works...
4
by: Michael R | last post by:
Does anyone know of such a way, or maybe have encountered an ActiveX control, that is able to have colors of conditional formatting on the drop-down list of a Combo box, besides the Combo box...
4
by: festerian | last post by:
Hi everybody - I'm a new access user and would appreciate some help. I'm trying to create a form, on which I'm trying to disable/enable a combo box, based on the value entered in another combo box...
4
by: slinky | last post by:
Thanks in advance... I have a continuous style form with a field for each record called "STATUS". I simply want to have the form load and if the value of the textbox is "Inactive" I want the...
6
by: BUmed | last post by:
Hi all I’m trying to figure this out. But help is needed. I have a combo box called fcmFLAG with 5 options (problem, hold off, call, withdrew and ineligible). What I would like to do is have the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.