473,386 Members | 1,867 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,386 software developers and data experts.

Change colour of text, based on combo box selection

7
i have a combo box (combo box 1) in a form header that users use to selct item numbers from.
I also have a combo box (combo box 2) that users use to select a priority number (1,2,3) for that item. This is then stored on the items record.

I was wondering if the item has a priority 1 in combo box 2, then it could display the text in combo box 1 as red (or posibly the background, or something to make it stand out).

Also i would like priority 2 items to display as amber and priority 3 items to display as green.
Feb 22 '08 #1
7 6613
sierra7
446 Expert 256MB
Hi
The short answer is 'Yes'

If you want the colour to change immediately after combo2 has been set then you will need to put code in the After_Update event of combo2.

If you want the colours to persist and change according to the priority when you are browsing through the records you will have to put the same code into the On_Current event of the Form.

You could change the colour of the text in the combo or it's back colour, or if you wanted to go overboard you could change the colour of the Header section etc

Expand|Select|Wrap|Line Numbers
  1. Private Sub combo2_AfterUpdate()
  2. If Me.combo2 = 2 Then Me.combo2.BackColor = RGB(250, 0, 0)
  3. If Me.combo2 = 2 Then Me.combo2.ForeColor = RGB(255, 255, 255)
  4. If Me.combo2 = 2 Then Me.Form.Section(acHeader).BackColor = vbRed
  5. If Me.combo2 = 2 Then Me.Form.Section(acDetail).BackColor = vbBlack
  6. If Me.combo2 = 2 Then Me.Form.Section(acFooter).BackColor = vbBlue
  7. End Sub
You can use the set 'vb' colours or mix your own using the RGB() function.

Get the idea? (don't forget to drop the u in colour)

Sorry, I have just read your last line! You will have to use If ...ElseIf construction to do what you want. I'll let you do that bit and you can have fun mixing your amber and green colours !


S7
Feb 22 '08 #2
NeoPa
32,556 Expert Mod 16PB
I would rather suggest using a Select Case statement for this (personal preference and an alternative idea).
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo_Box_2_AfterUpdate()
  2.   Select Case [Combo Box 2]
  3.   Case 1
  4.     Me.[Combo Box 1].BackColor = vbRed
  5.   Case 2
  6.     Me.[Combo Box 1].BackColor = vbYellow
  7.     'Me.[Combo Box 1].BackColor = RGB(255, 128, 0)
  8.   Case 3
  9.     Me.[Combo Box 1].BackColor = vbGreen
  10.   End Select
  11. End Sub
If Yellow isn't a good enough match, then the (commented) RGB() line may be used instead. You can even play with the values to match the colour you want.
Good luck :)

PS. Hi Sierra. I didn't know you were a Brit too (spelling of colour) ;)
PPS. As is Nasher too by the looks of things :)
Feb 24 '08 #3
sierra7
446 Expert 256MB
PS. Hi Sierra. I didn't know you were a Brit too (spelling of colour) ;)
True!
I noticed that Nasher had spelt it 'correctly' too which was why I mentioned it because (not wanting to be condescending here Nasher) it was a Newbie sort of question, so a typo could compound the problem.

I thought I would help further by showing the syntax for reference to Header etc because I remember how long it took me the first time.

Incidentally, I feel that vbGreen is a misnomer. Grass is green, trees are green but the only time I have seen vbGreen has been inside a baby's nappy, or should that be diaper?
S7
Feb 24 '08 #4
NeoPa
32,556 Expert Mod 16PB
...
Incidentally, I feel that vbGreen is a misnomer. Grass is green, trees are green but the only time I have seen vbGreen has been inside a baby's nappy, or should that be diaper?
S7
Yes, I liked that you gave different examples of the code :)
As to vbGreen being a bit off, I think that as Green is a hue (Primary Colour) the value (65,280 or 0xFF00) is simply saying 100% of Green and 0% of both Red & Blue. How a graphics card (or more likely monitor) manages to express this is independant of the software I would think.

PS. Thanks for the reminder :( I've not had to deal with that sort of thing for many years :)
PPS. Congratulations on the 200 posts when you reply to this :D
Feb 24 '08 #5
sierra7
446 Expert 256MB
PPS. Congratulations on the 200 posts when you reply to this :D
Thank you. It's amazing how quickly they add up.

We must be sad doing this on a Sunday afternoon though!

Incidentally I have used you Case Statement on another thread for changing colours of a Tab Control

It get's repeatative after a bit doesn't it!

S7
Feb 24 '08 #6
Nasher
7
Cheers guys for the help.

And you guessed right, i am a english newbie, so that "color" spelling could have really messed things up for me. Well done for being so alert.
Feb 25 '08 #7
sierra7
446 Expert 256MB
Your welcome Nasher

Just looking over my first posting I hope you realise that it was intended to be a guide to the syntax for a SINGLE STATEMENT.

Looking at it now I think "Why did I put all those If's ?" Obviously, you would not write an 'If Statement' like this in a program if you wanted to change MULTIPLE attributes! (I'm sure you know how to write an If statement but have a look at the Help if you have been brought up on Java or C# or something)

NeoPa's suggestion to use 'Select Case' is far more elegant and I wish I could get into the habit of using it but my formative years were spent learning Fortran V and old habits die hard.

S7
Feb 25 '08 #8

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

Similar topics

2
by: Jeff Barry | last post by:
Hi, I wonder if any one can help, I'm pretty new to Access and I can't figure out how to change the contents of a combo box based on a selection I make in another. Let me explain I have a...
5
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
0
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
0
by: uthooker | last post by:
I have an Access form with some combo boxes in the Form Header that are enabled/disabled using conditional formatting based on the setting in a checkbox also in the Header (Combo box = Enabled by...
6
by: bammo | last post by:
MS Access 2003, Windows XP SP2, VBA I have a continuous form that allows edits and filters, but not deletions or additions. I filter the form based on combining selections the user makes in...
9
by: Marianne160 | last post by:
Hi, I know there are various answers to this problem available on the web but none of them seem to work for me. I am using Access 2003 to make a form to look up data from a table. I have so far...
2
by: SHAWTY721 | last post by:
I have a form that contains two combo boxes that are related to each other. I need to find a way to populate my text box based on the criteria of the two combo boxes so the appropriate number...
1
by: martin DH | last post by:
Hello, I have a unique situation, I believe. I have a form with unbound textboxes (frmEditReport) - most populate from a search query but one unbound textbox, txt_ReturnInfo, populates based on a...
1
by: peasedm | last post by:
Okay this one has me stumped. I have a table called Review_Statements with the following columns: statementid type statement1 statement2 statement3 I have a form called SR_Review with an...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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,...

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.