Using CanShrink

L

Lyne Savage

I have a report with multiple columns and rows. Each row is a record source
and has to stay together. I applied CanShrink to these rows because they are
sometimes blank, and I don't want anyone printing a half-blank report.

My problem is that CanShrink acts like fit to page. Some of the columns have
more data than others, and CanShrink shrinks these boxes...which messes up
the alignment of my borders. Is there a way to fix this? I am a beginner, so
please use detail.
 
J

John Spencer

If you use can shrink and want regular borders you have to set the textbox
control's border style to Transparent and use VBA to draw the lines.

Ken Sheridan posted this some time ago. If this doesn't work, then post back
- I know that Duane Hookom has similar code to draw grids around controls in
report's detail section.

Option Compare Database
Option Explicit
'Ken Sheridan

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

Dim lngHeight As Long
Dim X1 As Single
Dim Y1 As Single
Dim Y2 As Single
Dim X2 As Single

Me.DrawStyle = 0

' Find the height of the tallest control in the row
Dim C As Control
For Each C In Me.Section(0).Controls
If C.Height > lngHeight Then
lngHeight = C.Height
End If
Next C

If PrintCount = 1 Then
' Draw the box around the record
For Each C In Me.Section(0).Controls
X1 = C.Left
X2 = C.Left + C.Width
Y1 = C.Top
' add twenty twips at bottom to
' avoid tight cropping to text
Y2 = lngHeight + 20
Me.Line (X1, Y1)-(X2, Y2), vbBlack, B
Next C

' Call the DrawLine and DrawBox procedures
' The third (lngHeight) argument should be
' more than the maximum possible height of
' the section
DrawLine 3400, 0, 3400, 10000, 5
End If

End Sub

Sub DrawLine(lngLeft As Long, _
lngTop As Long, _
lngRight As Long, _
lngHeight As Long, _
intLineWidth As Integer)

Dim lngColor As Long

' Set scale to twips
Me.ScaleMode = 1
' Set line width in pixels
DrawWidth = intLineWidth
' Make colour black
lngColor = RGB(0, 0, 0)
' Draw line at specified distance from left margin
Me.Line (lngLeft, lngTop)-(lngRight, lngHeight), lngColor

End Sub
''''module ends''''

'Leave each control's BorderStyle property as Transparent, as the border is
drawn by the above code.

'Ken Sheridan
'Stafford, England

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 

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