Report- Automatically adjust the height of a control

Lucky33

Registered User.
Local time
Today, 15:38
Joined
Sep 3, 2011
Messages
57
I have a report that prints lab tests. One section has 4 columns that are framed. Only the first control (STest) expands to more than one line. The Can Grow works on this control and subsequently the section expands. I need a code that expands the height of the other three controls to match that of STest. I am using office 2010
Any help
Thanks:)
 
The Can Grow on the other controls should work too if you pad them up with the difference between both fields.
Code:
=[[COLOR="Blue"]MyField[/COLOR]] & String(Len([STest])-Len([[COLOR="blue"]MyField[/COLOR]]), " ")
 
Sorry if I did not make it more clear. The issue has nothing to do with Len([STest]). They contents of STest could be two words only, but each on one line, which triggers the Can Grow of the control. I don't think this code will work.
 
Actually i really understand what it does and that's why i explained myself. What your code will do, is adding spaces to the [MyField] field to match the string length of [STest]. If you have in [STest] two words with 3 letters each, but each on a separate line, the Len([STest]) will return 8, which will not force the Can Grow of the [MyField]. in addition, if Len([MyField]) is bigger than that of [STest] the result of Len([Stest])-Len([MyField] will be negative.
Sorry pal, this code will not run. Just to let you know, I did test it and it gave me errors all over
 
If you set the borders to transparent and use code to draw the lines around the controls, you'll get it as shown in the attached picture, (use the print option "Print Preview")
attachment.php

Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
  Dim intMaxHeight As Integer
  Dim ctl As Control
  'Find highest control in Detail section
  For Each ctl In Me.Section(0).Controls
    If ctl.Height > intMaxHeight Then
      intMaxHeight = ctl.Height
    End If
  Next
  'Draw a box around each control in Detail
  For Each ctl In Me.Section(0).Controls
    Me.Line (ctl.Left, ctl.Top)-Step(ctl.Width, intMaxHeight), vbBlack, B
  Next
End Sub
 

Attachments

  • CanGrow.jpg
    CanGrow.jpg
    11 KB · Views: 272
I tried the following procedure on the On Format property, it did not work but did not give any error either:
"
Dim lngTallest As Long
Dim ctl As Control

For Each ctl In Me.Detail.Controls
If ctl.ControlType = acTextBox Then
If ctl.Height > lngTallest Then lngTallest = ctl.Height
End If
Next

For Each ctl In Me.Detail.Controls
ctl.Height = lngTallest

End If

Next
"
thanks
 
Thank you JHB
it looks like we were posting at the same time.
I tried yours and it is working for an extent. While it took care of the initial problem, it created two issues, it is little complicated:
1- drawing a box around each control is not working as originally was set to be, as now it shows double lines, and i can't tell what controls they belong to
2- in this section there is a hidden control that is used in the On Format procedure that will hide any row that has no contents... your procedure is boxing even this control and showing it
i have attached 2 printouts, one before and one after your procedure. you can see the difference between the two, and to the far right of the After you can see the hidden control effect
i think the first issue can be handled with some formatting, while the other one, needs to add a line that excludes that control [STestID]
thanks for the help
 

Attachments

...
i think the first issue can be handled with some formatting, while the other one, needs to add a line that excludes that control [STestID]
thanks for the help
Without having your report/database I can't say what cause the first issue.
For solving purpose I would put in a MsgBox in the "For Each" loop, showing the control names, to test if some unexpected control names shows up.
The second issue can be solved on this way.
If it is only one control, then test for the control name like ctl.Name = [YourControlName] and then exclude it, if more controls then use the control's Tag property!
 
Last edited:
Tks J
I found the problem for the first issue. the original formatting of the first control to the left was not 0. I moved it to the extreme left which is much easier than changing the code to match the left property. the result was great.
as for the second issue, also, i could go around it and i removed that invisible control, so those borders at the far right also vanished
I am happy with the results and so is my clien.
so many thanks to all of you who helped me on this.
:)
 
Good you got it solved!

By the way, did you read my signature? :)
 
To tell you the truth i did not read your signature, but if you are insinuating about the thank you thumbs up, i already put one at the beginning of my last post. but may be i should press the one on the bottom, and for that i apologize, because i did not really pay attention to it but here it is because you really deserve it
 

Users who are viewing this thread

Back
Top Bottom