By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

Conditional formatting on a combo box

P: 2
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
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 344
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

P: 2
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

Expert 100+
P: 344
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

Post your reply

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