Solved

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

Posted on 2004-09-20
5
215 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

827 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