Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Background Color to Alternate with Each Detail section? 1

Status
Not open for further replies.

brettatexplace

Technical User
Mar 8, 2002
60
0
0
CA
I have a Detail section that I would like to alternate the background color when it is formated. (from gray to white so that this is used instead of putting a line between each detail) Can anyone suggest how to do VBA on the OnFormat section of the Detail. ie: Detail.BackColor = grey

I would like it to look like this

[COLOR=black gray]Detail A etc...........[/color]
Detail B etc...........
[COLOR=black gray]Detail C etc...........[/color]
Detail D etc...........

Thanks to all in advance!
 
I use this code in the detail print event (uses line method) - Dim the variables & constant in general declarations:

'Loop counter for background shading
Dim n As Integer
'Constant for # of lines per page
Const LinesPerPage As Integer = 29
'Variables for line method
Dim X1, X2, Y1, Y2 As Single
'Variable for shaded box dimension
Dim sBoxHeight As Single

Dim lBackColor As Long

'Detail Print code:

Me.ScaleMode = 5 '5 = inches
Me.FillStyle = 1 'Transparent

lBackColor = 15724527
iLineCount = 0
sBoxHeight = 0.23515

X1 = 0.05
Y1 = 0
X2 = 10.32
Y2 = sBoxHeight

For n = 1 To LinesPerPage
iLineCount = iLineCount + 1
If Not iLineCount Mod 2 = 0 Then
'"BF" = Box (rectangle), Filled
Me.Line (X1, Y1)-(X2, Y2), lBackColor, BF
End If
Y1 = Y2
Y2 = Y2 + sBoxHeight
Next n


I have great faith in fools; self-confidence my friends call it.
-Poe
 
It seems that you are filling a box behind??? My detail sections are not fixed heights, but grow or shrink depending on content. (as per line on page == details that fit on page) I tried it but got something weird.
 
To meet your specs, all you should need is code in the On Format event like:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If Me.Section(0).BackColor = vbWhite Then
        Me.Section(0).BackColor = 12632256
     Else
        Me.Section(0).BackColor = vbWhite
    End If
End Sub

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Excellect, worked great. Thanks. (I didn't know weather the last detail would remember what color he was so I could just alternate)
 
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    'Michael Red.   2/13/2002.      To 'Toggle the backolor, which
    'Provides alternate line shading
    Const XorToggle = 4144959

    Me.Detail.BackColor = Me.Detail.BackColor Xor XorToggle

End Sub


MichaelRed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top