Conditional Formatting

G

Guest

I am working on a form that I need to have the fields turn various colors. I
have 4 conditions but can only do 3 using the conditional format option. Is
there a way to add more? Thanks for any info you can give me.
 
G

Guest

You can use VBA code as an alternative. Here is an example for setting the
backcolor of a text box. Note that I can add any number of Case statements:

Private Sub SetStatusColor()
'Set color display of txtStatus text box
Select Case txtElapsedDays.Value
Case 0 To 120 'Zero to 120 Days
txtStatus.BackColor = 32768 'Green
Case 121 To 180 '121 To 180 Days
txtStatus.BackColor = 65535 'Yellow
Case Is > 180 'Greater than 180 Days
txtStatus.BackColor = 255 'Red
Case Else '
txtStatus.BackColor = 12632256 'Grey
End Select

End Sub


Call the SetStatusColor subroutine wherever it makes sense. For example,
since I'm dealing with date entries, I make a call in the BeforeUpdate event
procedure for a text box name "txtStartDate":

Private Sub txtStartDate_BeforeUpdate(Cancel As Integer)
Call SetStatusColor
End Sub


And in Form_Current:

Private Sub Form_Current()
On Error GoTo ErrorHandler
Call DisplayChoices
Call SetStatusColor
Exit Sub
ErrorHandler:
MsgBox Err.Number & ": " & Err.Description
Resume Next
End Sub

Here is a KB article that shows how to use VBA code to achieve conditional
formatting in Access 97:

http://support.microsoft.com/kb/302705


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top