Keeping rows in a report the same size - new problem

J

judyg73

I am using the following code - which is working "almost" the way I need it.
My problem is that when the control expands to allow for the tallest control,
then it puts an extra line in another control on the page. It seems to be
putting the extra line in approximately the same spot at the top of the page.
The line only appears if one of the controls on the page has adjusted to
accomodate all of the data in the memo field. If everything fits in the
control that is set to a specific size, then there is no line. This report
is 2 pages long which includes a sub report that I have on the second page.
The sub report is using this same code. I have several reports that I am
going to need to use this code in, so any suggestions would be appreciated.

In the Detail Section, set each control's Border property to
Transparent.
Set the Detail Section's CanGrow property to Yes.
Set the Memo field's CanGrow property to Yes.
Set the Memo field's CanShrink property to No.
Size all of the controls to the same Height.

Place the following code in the Report Detail Print event:

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
' draws a box around each control,
' set to the height of the tallest control on that line.

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

' 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
Y2 = lngHeight
Me.Line (X1, Y1)-(X2, Y2), vbBlack, B
Next c

End Sub
 
K

Ken Sheridan

While its easy enough to draw a continuous vertical line between controls of
varying height (i.e. which can grow) I don't know of any way of doing it with
boxes. All controls in a row can be enclosed in same size boxes of the depth
of the deepest after it grows *provided that* all are of the same width,
which is probably not something you'd normally want, so its not really a
generic solution. The way to do it however is as follows:

1. Set the design heights of each control to the minimum height required as
usual.
2. Set the widths of each control to the same value.
3. Set the CanGrow property of the section and the relevant controls to True.
4. Copy the control which will grow the most and paste copies over each of
the other controls, aligning them exactly on top of each.
5. Set the BackColor property of the copy controls you pasted over the
other control in 4 to white (or whatever colour the background of the section
is if different). This will hide the text in these controls.
6. Select all of copy controls you pasted over the other control in 4 and
set their BorderStyle property to Solid, and their BorderColor and
BorderWidth properties as desired.
7. With the same controls still selected select Send To Back from the
format menu.

When the report opens you should se the same size boxes around all of the
controls. What you are really seeing of course are the borders to each
control you pasted over the others, but as the text in these identical
controls is white you see only the border, so it appears to be a box.

Ken Sheridan
Stafford, England
 
B

Bob Quintal

I am using the following code - which is working "almost" the way
I need it. My problem is that when the control expands to allow
for the tallest control, then it puts an extra line in another
control on the page. It seems to be putting the extra line in
approximately the same spot at the top of the page.
The line only appears if one of the controls on the page has
adjusted to
accomodate all of the data in the memo field. If everything fits
in the control that is set to a specific size, then there is no
line. This report is 2 pages long which includes a sub report
that I have on the second page. The sub report is using this same
code. I have several reports that I am going to need to use this
code in, so any suggestions would be appreciated.

In the Detail Section, set each control's Border property to
Transparent.
Set the Detail Section's CanGrow property to Yes.
Set the Memo field's CanGrow property to Yes.
Set the Memo field's CanShrink property to No.
Size all of the controls to the same Height.

Place the following code in the Report Detail Print event:

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
' draws a box around each control,
' set to the height of the tallest control on that line.

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

' 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
Y2 = lngHeight
Me.Line (X1, Y1)-(X2, Y2), vbBlack, B
Next c

End Sub
Try modifying your code slightly, to just draw the vertical lines
with code. The horizontal lines are preset in the report.
 
K

Ken Sheridan

I can't really see why your code isn't working as expected. It looks to me
as though it should do the job. Make sure that all the controls have the
same value for their Top property as well as their Height property. Another
thing which might be worth trying is to make the drawing of the line
conditional on the PrintCount value:

If PrintCount = 1 Then
' Draw the box around the record
For Each c In Me.Section(0).Controls
X1 = c.Left
' and so on
End If

I wouldn't have thought it would affect the behaviour you are experiencing,
but its worth a try.

Ken Sheridan
Stafford, England
 

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