Forecolor Conditional Formating

J

JRB19683

I have a report where when the data value is null I want the label to be
grayed out. I used a basic If/then statment in VB and it worked fine in
Access 2003. When I upgraded to 2007 the statment no longer worked. Here is
what i have

If IsNull(Reports![medicine report]![DNR Total]) Then
Reports![medicine report]![DNR Total_label].Forecolor = 12632256
Else
Reports![medicine report]![DNR Total_label].Forecolor = 0
End If

Can anyone tell me why this does not work in 2007? Thanks.
 
J

JRB19683

I run the code in the on print format section of VBA. The label in on a
medicine report that has multiple fields all of which i used this same
if/then code.

Alex Dybenko said:
Hi
Where do you run this code? try to run it in report section format event,
where DNR Total_label is placed

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com


JRB19683 said:
I have a report where when the data value is null I want the label to be
grayed out. I used a basic If/then statment in VB and it worked fine in
Access 2003. When I upgraded to 2007 the statment no longer worked. Here
is
what i have

If IsNull(Reports![medicine report]![DNR Total]) Then
Reports![medicine report]![DNR Total_label].Forecolor =
12632256
Else
Reports![medicine report]![DNR Total_label].Forecolor = 0
End If

Can anyone tell me why this does not work in 2007? Thanks.
 
J

JRB19683

I have each control labeled and it is the label I want to change not the
control itself. If the control has a number (even zero) both will have a
forecolor of black but if there is a blank I want the label grayed out. Like
I said the code did what i wanted it to in 2003 but when i upgraded it no
longer worked.

Dale_Fye via AccessMonster.com said:
Are you sure you want the ForeColor set as you have indicated? That just
colors the value in the control, not the control. And if the value is NULL,
then there won't really be anything to color, will there? Maybe you want the
backcolor? What is the controls Back Style set to (transparent or normal)?

I know that most people don't bother with naming conventions on their reports,
but this is one time that I do. Whenever I have code behind the report, I
name the appropriate fields, using my standard naming convention.

If you put it in the format event of the appropriate section, you could write
it as:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

me.txt_DNR_Total.BackColor = IIF(Isnull(me.[DNR Total]), 13619151,
16777215)

End Sub

Alex said:
Hi
Where do you run this code? try to run it in report section format event,
where DNR Total_label is placed
I have a report where when the data value is null I want the label to be
grayed out. I used a basic If/then statment in VB and it worked fine in
[quoted text clipped - 10 lines]
Can anyone tell me why this does not work in 2007? Thanks.
 
D

Dirk Goldgar

JRB19683 said:
I have a report where when the data value is null I want the label to be
grayed out. I used a basic If/then statment in VB and it worked fine in
Access 2003. When I upgraded to 2007 the statment no longer worked. Here
is
what i have

If IsNull(Reports![medicine report]![DNR Total]) Then
Reports![medicine report]![DNR Total_label].Forecolor =
12632256
Else
Reports![medicine report]![DNR Total_label].Forecolor = 0
End If

Can anyone tell me why this does not work in 2007? Thanks.


Can you verify that VBA is not disabled in this database? In Access 2007,
VBA is disabled by default unless the database is in a trusted location (as
identified in the Trust Center settings), or else is digitally signed with a
trusted certificate. If you set a breakpoint on the If statement, does the
code stop at the breakpoint?

By the way, if this code is running behind "medicine report", it would be
clearer and more efficient to replace your references to "Reports![medicine
report]![DNR Total]" with "Me![DNR Total]".
 

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