Solved

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

Posted on 2004-09-20
5
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 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