Conditional Formatting Problem.

jk12

Always getting problems.
Local time
Today, 21:53
Joined
Feb 16, 2006
Messages
91
Hi all. With one of my forms, I have a text box which will contain one of 8 different initials. I need each set of initials to appear highlighted in a different colour within the form is possible but more importantly in the report. I would normally use conditional formatting for a similar problem but it only allows 3 conditions which as you can see is less then I require. Is there any other solution to this problem so that I can view each set of initials highlighted differently. If its not possible in the form but only in the report, then that would be ok.

Thanks for any ideas.
 
Are these initals going to be highlited when you type them or before an update?
If it's before update then try:

Note the Case Statement. Replace the Case "#" with your initials and the 255 with the correct color codes your want.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    Select Case txtbox
      Case 1
        txtbox.ForeColor = 255
      Case 2
        txtbox.ForeColor = 255
      Case 3
        txtbox.ForeColor = 255
      Case 4
        txtbox.ForeColor = 255
      Case 5
        txtbox.ForeColor = 255
      Case 6
        txtbox.ForeColor = 255
      Case 7
        txtbox.ForeColor = 255
      Case 8
        txtbox.ForeColor = 255
    End Select
End Sub 'Form_BeforeUpdate

You can also mess around with the after update as well or text box before update. The example will work for any of the listed situations.
 
Last edited:
Try this:

Try this.
Code:
Private Sub txtbox_BeforeUpdate(Cancel As Integer)
    Select Case txtbox
      Case 1
        txtbox.ForeColor = 255
      Case 2
        txtbox.ForeColor = 255
      Case 3
        txtbox.ForeColor = 255
      Case 4
        txtbox.ForeColor = 255
      Case 5
        txtbox.ForeColor = 255
      Case 6
        txtbox.ForeColor = 255
      Case 7
        txtbox.ForeColor = 255
      Case 8
        txtbox.ForeColor = 255
      Case Else
        txtbox.ForeColor = 0
    End Select
End Sub 'Form_BeforeUpdate
 
Well I can't seem to get it to work. copied your code direct into my database and changed the Case 1 to Case PAC, Case 2 to PR etc and it just come up with an error. what am i missing?
 
Adding to before the initials need to be highlighted after they have been entered.
 
You need to put "Quotes" around your letters. Use an after_update procedure for your text box update.

Here's an example. Unzip and open the DB. I have included a text box, which formats "A-H" in different colors with an After_Update procedure.
 

Attachments

Last edited:
Thanks. Much better. Thanks for the help
 

Users who are viewing this thread

Back
Top Bottom