473,396 Members | 2,037 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,396 software developers and data experts.

how to change font color in combo box based on criteria

Hi experts,

Could you please help me with this situation? I'm using Access 2003 and I have a form with combo box containing lists of customer orders and status. What I need help on is when users choose customer order with status "C" then the font in the combo box for this customer order is red, else will remain black.
How can I do this? I tried using conditional formatting but it won't work.

Thank you so much...
Jul 15 '10 #1
12 22533
beacon
579 512MB
You can use VBA to accomplish this. In the BeforeUpdate event for the combobox, enter the following:

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourComboBox_BeforeUpdate()
  2.  
  3.      If Me.YourComboBox.Columns(2) = "C" Then 'This assumes that you only have 2 display columns in your combobox
  4.           Me.YourComboBox.ForeColor = vbRed
  5.      Else
  6.           Me.YourComboBox.ForeColor = vbBlack
  7.      End If
  8.  
  9. End Sub
  10.  
Jul 15 '10 #2
Thank you for the quick response.

When I tried to put your code, it didn't work quite well. when I choose from my combo box, it didn't change the value, instead it went back to the first value on the combo box list, for example, when I choose cust order 11111, it displayed cust order 00000 on the combo box since 00000 is the first cust order on the list. Am I missing something?
Jul 15 '10 #3
beacon
579 512MB
Can you post your code?
Jul 15 '10 #4
Hi Beacon,

sorry for the late reply...

here is the code that I have

for combo box, I called it txtcustorder
on the property, it has bound column -- 2
Row source type -- table/query
Row source --
Expand|Select|Wrap|Line Numbers
  1.  SELECT cust_ORDER.cust_ID,cust_ORDER.STATUS FROM cust_ORDER GROUP BY cust_ORDER.cust_ID, cust_ORDER.STATUS ORDER BY cust_ORDER.cust_ID; 
on the after update event:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub txtcustorder_afterUpdate()
  2.  
  3. If Me.txtcustorder.Column(2) = "C" Then       '
  4. Me.txtcustorder.ForeColor = vbRed
  5. Else
  6.  Me.txtcustorder.ForeColor = vbBlack
  7. End If
  8.  
  9. End Sub
  10.  
Please help....
Jul 16 '10 #5
Why is order status your bound column?
Jul 17 '10 #6
OldBirdman
675 512MB
In post #1, the problem is "...then the font in the combo box for this customer order is red, else will remain black." If that is the problem, then the answer is: It is not possible, at least in Access 2003.
Beacon in post #2 suggests:
Expand|Select|Wrap|Line Numbers
  1. Me.YourComboBox.ForeColor = vbRed 
but this will change all the text to red, not just the selected line.
In post #3, the test
Expand|Select|Wrap|Line Numbers
  1. If Me.txtcustorder.Column(2) = "C" Then ...
is incorrect. Columns are 'Zero Based'. The columns for the combobox are .Column(0) and .Column(1). There is no .Column(2).
Post #6 asks "Why is order status your bound column?" but this isn't getting to the issue. txtcustorder is an unbound control, and ConfusedMay is never referencing txtcustorder.value, only txtcustorder.Column(1). It is a good point to come back to, but not relevant to this question.
Why is the value 00000 when 11111 is selected? I would suspect there is more code somewhere that is setting txtcustorder to its original state. A ReQuery of the form perhaps
Jul 17 '10 #7
slenish
283 100+
Hello ConfusedMay,

I might be able to help you with this. I need a little bit more information though. You say you have a combo box and when you select a name in the combo box you want it to turn red if the order status is "C". My first question is the table you are pulling from how many columns do you have? Second, is the status "C" in a seperate column?

If you could provide a little more info on this I might be able to help.

Slen
Jul 19 '10 #8
beacon
579 512MB
@OldBirdman
OldBirdMan,

I tested my suggestion out and it works. True, all of the values in the combo box will turn red if the value selected is equal to the desired value, but it will return to black if a different value is selected.

Since it was my understanding that ConfusedMay simply wanted to the displayed/selected value to be red, this should have resolved the issue.

As for the column numbers, I tested a zero-based column and returned an error message, so I went with what worked for me despite my better judgement.
Jul 19 '10 #9
beacon
579 512MB
@ConfusedMay
Hi ConfusedMay,

One thing that I noticed right off is that you used the AfterUpdate event and not the BeforeUpdate event, which is what I originally suggested.

After reading OldBirdMan's post, I feel it's necessary to ask you to clarify what you are asking for as the solution I provided you with will, in fact, turn all items in the combobox red if you view them when selecting the dropdown. The value will only be red or black in the text box portion of the combobox, but I'm now not sure if this is what you were after or not.
Jul 19 '10 #10
Hi all,

Thank you so much for all your replies and yes beacon, my bad, I created it on the after update when it's suppose to be on the before update.

before update is worked now...

Thank you....
Jul 19 '10 #11
Hi Beacon,

Just one quick question, why I need to put the code on the before update event instead of the after update event? I thought whatever that I need code change after whatever stuff that I enter, I need to put it on the after update event. Sorry if the question is kind of dumb, I'm new at VBA and still has a lot to learn.

Thank you...
Jul 19 '10 #12
beacon
579 512MB
@ConfusedMay
I could be way off base on this, so don't take what I say as a statement of fact as it's only based on my understanding, however limited that may be.

With AfterUpdate, you're expecting the record to be saved before some action is taken. With a combobox, any change in the value of the combobox doesn't necessarily save/change the record unless explicitly coded to do so. That's the reason why nothing appeared to happen when you used AfterUpdate. However, had you moved to another record, and come back to the record you changed, chances are the value would have been red.

On the flip side, the BeforeUpdate event fires before the record is saved/changed, which makes it the likely event to use with most controls, especially those that don't involve saving a record. In my experience, BeforeUpdate is the best, if not the only option when modifying a form with unbound controls that are used specifically to improve the functionality for the user (such as modifying a control based on a different control with an expression that isn't bound to a field on an underlying table).

Like I said, this is only what I've been able to ascertain from developing my own databases and may be far from the reality of it all. There's some reading online if you want to study up on it...just search "difference between beforeupdate and afterupdate events".

Hope this helps...
Jul 19 '10 #13

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

Similar topics

1
by: Ahmad Hassan | last post by:
How do you change the foreground color and font on the console using Visual C++ 6.0
1
by: Ada | last post by:
i'm trying to use Regex to match a 4 number group pattern. once a match is found, write it to RichTextBox in red. test data: This is my 4567 test data. 1234this is another line of data. Here's...
0
by: Sreejumon[MVP] | last post by:
Hi, Here you go -> Right clikc the datagrid -> Property builder -> format-> header Then set the fontcolor and back color. regadrs
3
by: Wes McCaslin | last post by:
I have create a MDI form and a child form.I have a menu with a option to change the font color to red,blue, or yellow. but for some reason i can't figure this out. thanks wes
7
by: beetdocta | last post by:
hello i was wondering is it possible in visual basic .net to change the color of certain words or phrases without changing the color of all the text in the lable or without having to create a new...
0
by: Meera | last post by:
How to write a macro for the following purpose. 1.Search the lines start with "//*"in CSharp file . 2.Change font color of that lines. I wrote the following code Sub ChangeFontColor() Dim...
2
by: flash | last post by:
1-When the mouse is over the course title. Its description should appear. When it the mouse is out, the description should disappear. 2-when double click on a word, its color changes to...
13
by: plsHelpMe | last post by:
Hello Frens, I am supposed to show a fading effect on the options of a multiselect tag. To achieve this i used something like this: document.getElementById(toTargetId).style.backgroundColor =...
2
by: nspader | last post by:
Hello All, I have a DB that shows information generated on a form setup to look like a calendar. I am working with Windows 2000 and Access 2000. Public Sub PutInData() On Error GoTo...
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: 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?
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.