Shading every alternative record

L

Lachlan Sharp

I am using the Detail Sections OnPrint Event to shade
every alternative record using the Line method. I have
included the code I am using:

' ** Access 2000 ********************
Option Compare Database
Option Explicit

Dim Odd As Boolean

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

Dim X1 As Single, Y1 As Single
Dim X2 As Single, Y2 As Single
Dim Color As Long

If PrintCount = 1 Then ' Only toggle the shading for a
new record
Odd = Not Odd ' Toogle boolean value
End If

' Specify unit of measurement for coordinates on a
page...
Me.ScaleMode = 3 ' reports width and height
dimensions are returned in twips

' Set upper left corner of rectangle
X1 = 0
Y1 = 0

' Set rectangle to print the width and height of the
details section
X2 = Me.Width
Y2 = Me.Section(0).Height

Me.DrawWidth = 1 ' Width of the line (in pixels).
Color = 10079487

' Draw the line with the Line method.
If Odd Then
Me.Line (X1, Y1)-(X2, Y2), Color, BF
End If

End Sub
' ********************************

This code has worked well for me except under certain
circumstances where the height of the rectangle drawn is
less than the height of the details section. One
circumstance is if a texbox is 'significantly' too narrow
for the text to be displayed and hence has to grow
greatly. I can't define significantly, but there is a
point beyond which the text box can be undersized in
design view that the rectangle drawn is no longer the
correct height. Up to that point the code works fine.

The other circumstance has been where I've used a very
small font size (Arial font, 4 points) and the rectangle
drawn is always the height of the details section in
design view, not the height of the details section as it's
printed.

What is causing the anomaly with the Detail Section height
being returned, how can I change my code to work around it?

I am under the understanding that if I make the height,
using the line method, 22 inches (which is the max) then
it will automatically be fitted to the height of the
details section. However because I'm using twips as my
measurment system I'm not sure what the maximum height
would be. It also does not seem a very elgant way of
solving the problem. I am also using the line method to
draw grids around report data (elsewhere) hence my desire
to use twips to properly identify the location of controls
using their top/left/width/height properties.

Thanks

Lachlan Sharp
 
M

Marshall Barton

You're making a mountain out of a mole hill. The approach
you're attempting to use could be made to work, except for
one fatal flaw that you haven't spotted yet. Let me ignore
all of your questions and focus on the objective.

Instead of drawing a rectangle, set all of the labels and
text boxes BackStyle property to Transparent so all you have
to do is set the detail section's BackColor using code:

If Me.Section(0).BackColor = vbWhite Then
Me.Section(0).BackColor = RGB(153,204,255)
Else
Me.Section(0).BackColor = vbWhite
End If

That should be all it takes.

P.S. there are 1440 twips per inch so the maximum height of
a section is about 32,000 twips.
 
L

Lachlan Sharp

Thankyou for your help. I didn't ever occur to me that the
backcolour of the section could be changed individually
for each record.
-----Original Message-----
You're making a mountain out of a mole hill. The approach
you're attempting to use could be made to work, except for
one fatal flaw that you haven't spotted yet. Let me ignore
all of your questions and focus on the objective.

Instead of drawing a rectangle, set all of the labels and
text boxes BackStyle property to Transparent so all you have
to do is set the detail section's BackColor using code:

If Me.Section(0).BackColor = vbWhite Then
Me.Section(0).BackColor = RGB(153,204,255)
Else
Me.Section(0).BackColor = vbWhite
End If

That should be all it takes.

P.S. there are 1440 twips per inch so the maximum height of
a section is about 32,000 twips.
--
Marsh
MVP [MS Access]



Lachlan said:
I am using the Detail Sections OnPrint Event to shade
every alternative record using the Line method. I have
included the code I am using:

' ** Access 2000 ********************
Option Compare Database
Option Explicit

Dim Odd As Boolean

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

Dim X1 As Single, Y1 As Single
Dim X2 As Single, Y2 As Single
Dim Color As Long

If PrintCount = 1 Then ' Only toggle the shading for a
new record
Odd = Not Odd ' Toogle boolean value
End If

' Specify unit of measurement for coordinates on a
page...
Me.ScaleMode = 3 ' reports width and height
dimensions are returned in twips

' Set upper left corner of rectangle
X1 = 0
Y1 = 0

' Set rectangle to print the width and height of the
details section
X2 = Me.Width
Y2 = Me.Section(0).Height

Me.DrawWidth = 1 ' Width of the line (in pixels).
Color = 10079487

' Draw the line with the Line method.
If Odd Then
Me.Line (X1, Y1)-(X2, Y2), Color, BF
End If

End Sub
' ********************************

This code has worked well for me except under certain
circumstances where the height of the rectangle drawn is
less than the height of the details section. One
circumstance is if a texbox is 'significantly' too narrow
for the text to be displayed and hence has to grow
greatly. I can't define significantly, but there is a
point beyond which the text box can be undersized in
design view that the rectangle drawn is no longer the
correct height. Up to that point the code works fine.

The other circumstance has been where I've used a very
small font size (Arial font, 4 points) and the rectangle
drawn is always the height of the details section in
design view, not the height of the details section as it's
printed.

What is causing the anomaly with the Detail Section height
being returned, how can I change my code to work around it?

I am under the understanding that if I make the height,
using the line method, 22 inches (which is the max) then
it will automatically be fitted to the height of the
details section. However because I'm using twips as my
measurment system I'm not sure what the maximum height
would be. It also does not seem a very elgant way of
solving the problem. I am also using the line method to
draw grids around report data (elsewhere) hence my desire
to use twips to properly identify the location of controls
using their top/left/width/height properties.

.
 

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