Conditional Formatting error.

J

Jim Shortslef

I have been using code to set up conditional formatting in
a form with no problem. Everything has been working as
expected. The problem is that I am now trying to use
conditional formatting on a report that is called by the
form. When the form is opened I get the following error:

Run-time error '7966':

The Format condition number you specified is greater then
the number of format conditions.

Below is the code for setting up the conditional formating
in my report.

Sub RColor(Loc As String, NumEnt As Integer, B1Max As
Single, B2Max As Single, B3Max As Single)

Dim objFrc1 As FormatCondition
Dim Red As Long, Green As Long, Yellow As Long, Orange As
Long

Red = RGB(255, 25, 50)
Green = RGB(0, 150, 0)
Yellow = RGB(250, 250, 50)
Orange = RGB(255, 125, 0)

Set objFrc1 = Reports!rpt_RankFinal!
(Loc).FormatConditions.Add(acFieldValue, acBetween, 0,
B1Max)
Set objFrc1 = Reports!rpt_RankFinal!
(Loc).FormatConditions.Add(acFieldValue, acBetween, B1Max,
B2Max)
Set objFrc1 = Reports!rpt_RankFinal!
(Loc).FormatConditions.Add(acFieldValue, acBetween, B2Max,
B3Max)

With Reports!rpt_RankFinal!(Loc).FormatConditions(0)
.BackColor = Green
.ForeColor = Green
End With

With Reports!rpt_RankFinal!(Loc).FormatConditions(1)
.BackColor = Yellow
.ForeColor = Yellow
End With

With Reports!rpt_RankFinal!(Loc).FormatConditions(2)
.BackColor = Orange
.ForeColor = Orange
End With

End Sub

I have spent 2 days trying to figure out why I get this
error. Can it be that I can not use conditional
formatting twice at the same time? (In my form and then in
my report which is opened by the form?) Any suggestions
on what is going on here would be appreciated. What do I
need to do to get the formatting working in my report?

Jim
 
S

Stephen Lebans

Have you tried calling the Delete method of the FormatConditions object
before adding new entries to the collection?
(Loc).FormatConditions.Delete

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 

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