The example procedure tests height of multiple controls and uses the one that is greatest. If you are certain about which control will grow most, then can reference only that control for the height and eliminate the first array loop.
I tested the original code in post 3 and it works for me. Although somehow I am getting an extra box drawn. Not understanding why the code has the second conditional If for generating box, the code to draw is identical. I removed the If code and left only the one line and it still works, although still get the extra box. Ah, finally figured out cause. Had to change code to:
For lngCounter = 0 To UBound(strcontrol) - 1
I expect getting the label borders to perfectly line up with the code generated boxes will require similar code in the Page Format event. Tested and that does work.
Might want to set or increase textbox and label Margin properties. Make sure all textboxes CanGrow Yes. CanShrink No if you want to be able to open in Report view and still view data.
Be aware Print and Format events only trigger for PrintPreview or direct to printer.
Code is easier to read with indentation.
Code:
Option Compare Database
Option Explicit
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
On Error Resume Next
Dim lngCounter As Long, dblMaxHeight As Double
dblMaxHeight = 0
ReDim strcontrol(4)
strcontrol(0) = "UPC"
strcontrol(1) = "VendorSku"
strcontrol(2) = "Descrip"
strcontrol(3) = "Qty"
For lngCounter = 0 To UBound(strcontrol) - 1
If Me(strcontrol(lngCounter)).Height > dblMaxHeight Then dblMaxHeight = Me(strcontrol(lngCounter)).Height
Next
For lngCounter = 0 To UBound(strcontrol) - 1
Me.Line (Me(strcontrol(lngCounter)).Left, Me(strcontrol(lngCounter)).Top)-Step(Me(strcontrol(lngCounter)).Width, dblMaxHeight), , B
Next
End Sub
Private Sub PageHeaderSection_Print(Cancel As Integer, PrintCount As Integer)
On Error Resume Next
Dim lngCounter As Long
ReDim strcontrol(4)
strcontrol(0) = "Label0"
strcontrol(1) = "Label1"
strcontrol(2) = "Label2"
strcontrol(3) = "Label3"
For lngCounter = 0 To UBound(strcontrol) - 1
Me.Line (Me(strcontrol(lngCounter)).Left, Me(strcontrol(lngCounter)).Top)-Step(Me(strcontrol(lngCounter)).Width, Me(strcontrol(lngCounter)).Height), , B
Next
End Sub
Think would not want to save "Product description goes here" in table.