473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to format color in a combo box depending on value?

158 100+
I have a combo box that I would like to shade the background depending on the value.

this is what I have but it doesn't work:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If ([Provenance].Value = "Appointment") Then [Provenance].BackColor = ADC0D9
  3. ElseIf ([Provenance].Value = "Journal") Then [Provenance].BackColor = DFA7A5
  4. ElseIf ([Provenance].Value = "Project") Then [Provenance].BackColor = BFB2CF
  5. ElseIf ([Provenance].Value = "Repairs") Then [Provenance].BackColor = CDDCAF
  6. ElseIf ([Provenance].Value = "Symbiosis") Then [Provenance].BackColor = F9CDAA
  7.  
any idea on how to fix this?
I am using access 2007
Jan 21 '11 #1

✓ answered by Stewart Ross

Hi. Had this one been possible your value tests would have been done from the AfterUpdate event of the combo rather than its BeforeUpdate event - it is fired after the change of value takes place, and at that point you can certainly change the backcolor property of the control if necessary.

However, as you are using a continuous form this approach will not work. The reason is that any change you make to the backcolor property of the combo will apply simultaneously to ALL the data rows currently shown in your form. In design view you see just one control, and that single instance is repeated for all the rows displayed in the continuous form. Whatever is done to its properties in code affects all instances of that control at the same time.

In datasheet view you are even more restricted, as you don't get the chance to display custom colours at all.

It was this kind of limitation that conditional formatting addressed, but as you have said the limitation to three conditions does not fulfil your needs.

-Stewart

6 4311
beacon
579 512MB
Are you using a continuous form?

If not, try using the BeforeUpdate event for the combobox instead of the Form_Current event.
Jan 22 '11 #2
jaad
158 100+
Yes was in a continuous form, I made the default view data sheet now as it seem a little clearer to read. I have a 3 conditional formatting on a date field which work but the other field [Provenance] requires 5 different colors. I am going to try to put in the before update as you suggested and will report back.
Jan 22 '11 #3
jaad
158 100+
ok I've tried it and it doesn't work. Maybe I should mention that the combo box use a value list and the field type is text; I didn't mentioned that in my original post. I tried using [1] instead of [Provenance] because Appointment is the first one on the list but that doesn't work either
Jan 22 '11 #4
Stewart Ross
2,545 Expert Mod 2GB
Hi. Had this one been possible your value tests would have been done from the AfterUpdate event of the combo rather than its BeforeUpdate event - it is fired after the change of value takes place, and at that point you can certainly change the backcolor property of the control if necessary.

However, as you are using a continuous form this approach will not work. The reason is that any change you make to the backcolor property of the combo will apply simultaneously to ALL the data rows currently shown in your form. In design view you see just one control, and that single instance is repeated for all the rows displayed in the continuous form. Whatever is done to its properties in code affects all instances of that control at the same time.

In datasheet view you are even more restricted, as you don't get the chance to display custom colours at all.

It was this kind of limitation that conditional formatting addressed, but as you have said the limitation to three conditions does not fulfil your needs.

-Stewart
Jan 22 '11 #5
mshmyob
904 Expert 512MB
If you are looking to change the background of different controls on a Continous subform then you can check out my demo here http://bytes.com/topic/access/insigh...imited-colours in the insights.

You can have as many conditional colour changes as you want and apply them to as many controls as you want or even an entire row. This technique only works in AC2007.

cheers,
Jan 22 '11 #6
beacon
579 512MB
Thank you for correcting me Stewart. I was in a rush when I posted and obviously didn't think it through very well.
Jan 22 '11 #7

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

Similar topics

1
by: Bala | last post by:
How do i change the back color of the MessageBox
1
by: Bala | last post by:
How do i change the back color of messagebox
1
by: Luminal | last post by:
greetings is it possible to change the back color of text on the groupbox control? I change the back color property of groupbox but the label's text back color stay the same (grey). If it is...
5
by: Peter | last post by:
I'm coding a startup form whose back color is Linear Gradient ,and now I want to place a label on the form. I don't like any back color of the label,just wants it to be transaprent, Is it possible?...
1
by: rockdale | last post by:
Hi, All I have an datagrid with alternating color, I also want the back-color of my textbox in ItemTemplate also appears alternating, how could I do that? <asp:datagrid id="dgridEmpHours"...
1
by: C. Hughes | last post by:
Hi, I have a VB.NET 2005 application with a standard tabcontrol on it. The application has the 'VisualStyles' enabled giving it an 'XP' look. For some reason, the back color of this tabpane has...
4
Tommyivens
by: Tommyivens | last post by:
Hi All I made a form with a few combo boxes that follows up on each other, so if you choose in the first combo a value then you can only choose in the next combo a value that is a result of the...
2
by: maralfarshadi | last post by:
Hello In my JSP, I have several comboboxes (located in several forms in one JSP). In the onChange event , I have : onchange="submit()" My combobox have the values : Select Item Action 1...
0
by: sweatha | last post by:
Hello Friends I have created the project with 2 forms. In the first form, I have 2 buttons. The first button has the backcolor as "fusia" by default. If I click the button means then backcolor of...
3
by: evenlater | last post by:
Using Access 2007, I've found that combo box back colors change to transparent from normal inconsistently for no reason I can discern. Never had that problem in previous versions of Access. I do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.