Change backgroundcolor if next record is different

J

johan

Hoi,

Can somebody help me out.

In a form, and also in the report, I have a column with data.
When the next record datavalue is different, then the backgroundcolor
(only for this datafield in this record)should be change. Is there a
module which I can set on the field event proporties.
When it's not possible in the field event proporties, maybe possible
as a conditionalformatting formula ?

Regards,
 
D

Dale Fye

johan,

Don't know how to do this in a continuous form. You might want to check out
Steve Leban's website (http://www.lebans.com/). He has a lot of samples of
how to do things with continuous forms.

In a report, you can play with the detail sections background property in
the Details Format event. The following example alternates the background
color of the rows in a report between Red and Black (not very good choices
but shows you the idea).

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

Static BackcolorFlag as variant

'BackcolorFlag will only be null the first time into this routine
If IsNull(BackcolorFlag) Then
BackcolorFlag = 0
Else
BackcolorFlag = 1 - BackcolorFlag
End If

Me.Detail.BackColor = IIf(BackcolorFlag = 0, 0, 255)

End Sub

If you want to change the background color whenever the value in a
particular field changes, you might do something like:

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

Static SomeValue As Variant
Static BackcolorFlag as integer

'SomeValue will only be null the first time into this routine
If IsNull(SomeValue) Then
BackcolorFlag = 0
SomeValue = me.txt_SomeField
Elseif SomeValue <> me.txt_SomeField then
BackcolorFlag = 1 - BackcolorFlag
SomeValue = me.txt_SomeField
End If

'Change the vales of the True and False parameter to
' the backcolors you want to alternate between
Me.Detail.BackColor = IIf(BackcolorFlag = 0, 0, 255)

End Sub

HTH
Dale
 

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