Color coded field on condition

R

Ray

I want to highlight the background color to red in 7 days before and after
the date in the field of [Next] with following code in the even procedure of
On Print in Detail Section of the report without success. Your advice is
appreciated.

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

If Date - Me.[Next] >= -7 And Date - Me.[Next] <= 7 Then

Me![Next].BackColor = vbRed
Me![Next].ForeColor = vbWhite
Me![Next].FontBold = True
Else
Me![Next].BackColor = vbWhite
Me![Next].ForeColor = vbBlack
Me![Next].FontBold = False
End If

End Sub

Thanks,

Ray
 
F

fredg

Ray said:
I want to highlight the background color to red in 7 days before and after
the date in the field of [Next] with following code in the even procedure of
On Print in Detail Section of the report without success. Your advice is
appreciated.

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

If Date - Me.[Next] >= -7 And Date - Me.[Next] <= 7 Then

Me![Next].BackColor = vbRed
Me![Next].ForeColor = vbWhite
Me![Next].FontBold = True
Else
Me![Next].BackColor = vbWhite
Me![Next].ForeColor = vbBlack
Me![Next].FontBold = False
End If

End Sub

Thanks,

Ray
Ray,
Be aware that -6 is LESS THAN -7, not greater.

If you are doing this in code, I would suggest the Detail Format event.

If DateDiff("d",[Next],Date) <= -7 OR DateDiff("d",[Next],Date)<= 7 Then
Me![Next].BackColor = vbRed
Me![Next].ForeColor = vbWhite
Me![Next].FontBold = True
Else
Me![Next].BackColor = vbWhite
Me![Next].ForeColor = vbBlack
Me![Next].FontBold = False
End If

If you have Access 2000 or later, you can use the control's
Conditonal Formatting property.
Select the Control, then Format + Conditional Formatting

Select:
Expression Is
in the Condition1 drop-down box.
Set the Condition to:

DateDiff("d",[ADate],Date())<=-7 OR DateDiff("d",[ADate],Date())<=7

on one line.
Do NOT precede the line with an = sign.
Note, you need to use Date() in the above expression, not Date as in VBA
code.
Select your colors, etc. for the conditon.
 

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