Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

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 …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 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