Solved

Need a VB code to change font color of a text based based on value

Posted on 2004-09-20
5
209 Views
Last Modified: 2010-05-02
This is in access, and I have a text box which looks up a certain value for a record, and the value will either be a 1 or 2, and then the text box displays some corresponding text.  

Now, I would like to find some code where if the value is a 1, i can make it red, and if it is a 2, i can make the text green.  Can text box text color be changed like that?  This is access 97, so rich text boxs are not allowed (to my knowledge)
0
Comment
Question by:salival
  • 2
  • 2
5 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 500 total points
ID: 12107767
The Forecolor property is what you need to change,

Select case x
Case 1: Text1.ForeColor = vbRed
Case 2: Text1.ForeColor = vbGreen
end Select

Other examples:

Text1.ForeColor = RGB(100, 200, 64)
Text1.Forecolor = &h00FF00
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12111957
In Access you can also use Conditional Formatting to accomplish this.  But I don't remember if that was available in Access 97 or not.  Do you need to do this in a report or on a form?
0
 

Author Comment

by:salival
ID: 12112665
on a form
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12112983
Is the ForeColor property working for you then?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12113573
I believe Conditional Formatting is associated with reports and not forms.  On a form you just need to decide how to trigger the change and then use the code that Erick37 provided.  Since this is on a form I'm guessing you want the change to take affect when the form is displayed initially and each time a new record is shown.  Possibly also if the value of the field changes.  Pick out which events will cover those changes and insert Erick37's code in those events.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now