Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Color in Tabular Forms

Status
Not open for further replies.

Phudsen

Technical User
Mar 7, 2003
136
A2
Hi,

I have a tabular form that is working fine. It has a field called "Gender". The values are M for Male, F for Female and E for Exam.

I want to display M in blue, F in Red and E in black.

I used the following code:

Dim lngRed As Long, lngBlue As Long, lngBlack As Long
lngRed = RGB(255, 0, 0)
lngBlack = RGB(0, 0, 0)
lngBlue = RGB(0, 0, 255)

If Me.Gender = M Then
Me.Gender.ForeColor = IngBlue
ElseIf Me.Gender = F Then
Me.Gender.ForeColor = IngRed
Else
Me.Gender.ForeColor = IngBlack
End If

The problem:
- The color does not change
- I get no error from the code
-I also tried putting the gender value between quotation marks, but nothing happened.
- I tried the code once in On Current event and once in On Open event, but nothing happened.

Is the code correct or Tabular forms can't be controled in this way?

Best regards
Paulin
 
If you by tabular mean "continuous form", then take a look at conditional formatting from the format menu. Chose "Expression is", then enter the expression (for instance [Gender]="M"), alter the format ...

If you'd used quotes ("M", "F"...) then your initial code would have given a result on the row it was executed on (hint - always use Option Explicit at the top of each module)

Roy-Vidar
 
Hi Roy,

Thank you for your reply.

Yes it is a continuous form. I tried the conditional formatting. It worked fine, thanks a lot.

Question:
The conditional formatting gives 3 conditions only, suppose I have more. Example, each day of the week in a different color. What to do in this case.

Also what is wrong with my code, why isn't it working?

Thanks a million
 
With the default format, you have four formats.

Back in the "old days", people were doing "conditional" formatting too - but it's somewhat more involved. See for instance
Why the code doesn't work - well - when working with a continuous form, what you see isn't many controls, but many instances of the same control - so change a property of a control, and you've changed all instances of it.

Roy-Vidar
 
Thank you Roy,

It is clear now why my code did not work.

So, am I stuck now with four formatting only?

Thanks a lot
Pauling
 
How are ya Phudsen . . .

To have more than four conditional formats (actually three plus the default), in VBA have a look at the [blue]FormatConditions Collection[/blue] . . .

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top