Hmmmmmmmmmm,
Never stop being taught "new" (to me) features.
Thanks (and kudos) to JohnLowell.
Being a creature of laziness, I reviewed and generalized his code - using the secrete ingreedient of OnPrint knows the 'rendered Height' of the objects!
While the TRULY lazy would reduce these to a single function, I chose to provide seperate routines for the Single line and the BOX.
The single line control ONLY provides for vertical lines in on the report, and has the option of placing the line to the LEFT or RIGHT of the specified control.
The Box routine requires two (2) controls, and palaces a box around the "out side" of them, using their collective extreme locations.
Further, each routine may (SHOULD) be placed in a general module, so there is no need to copy the functions (procedures) for each report, or to modiify the routine for different controls on the report(s).
This one draws a box around the controls
Code:
Public Function basVarBox(Form As String, ULCtrl As String, LRCtrl As String) As String
'Michael Red, 12/1/2001
'Draw a "Box" around a group of controls in a Report
'where the controls' Properties CanGrow and CanShrink may be TRUE
'NOTE: The two controls "Should" form a "Box w/o any OTHER controls
'overlapping the boarder.
Dim X1 As Double 'Left
Dim Y1 As Double 'Top
Dim X2 As Double 'Right
Dim Y2 As Double 'Bottom
Dim Offset As Long 'Border / Whitspace Width
Dim LnColor As Double 'Line color to Draw
Dim tmpXY(1) As Double 'Temp To check MinMax of X | Y Point
'Must be CALED from OnPrint Event of Report. Similar to:
'Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
' MyCoords = basVarBox(Me.name, Expression.name, Text1.name)
'End Sub
'Where:
' MyCoords is a Dummy (String) variable
' Me.Name is a constant (returns the Name of the REPORT)
' Expression(.Name) is the "name" of one of the two Controls. and
' Text1(.Name) is the "name" of the other control
'Left X (Min of Left of the Controls)
tmpXY(0) = Reports(Form).Controls(ULCtrl).Left
tmpXY(1) = Reports(Form).Controls(LRCtrl).Left
If (tmpXY(0) < tmpXY(1)) Then
X1 = tmpXY(0)
Else
X1 = tmpXY(1)
End If
X1 = X1 - Offset
'Right X (Max of Left + Width of the Controls)
tmpXY(0) = Reports(Form).Controls(ULCtrl).Left + Reports(Form).Controls(ULCtrl).Width
tmpXY(1) = Reports(Form).Controls(LRCtrl).Left + Reports(Form).Controls(LRCtrl).Width
If (tmpXY(0) > tmpXY(1)) Then
X2 = tmpXY(0)
Else
X2 = tmpXY(1)
End If
X2 = X2 + Offset
'Top Y (Min of Top of the Controls)
tmpXY(0) = Reports(Form).Controls(ULCtrl).Top
tmpXY(1) = Reports(Form).Controls(LRCtrl).Top
If (tmpXY(0) < tmpXY(1)) Then
Y1 = tmpXY(0)
Else
Y1 = tmpXY(1)
End If
Y1 = Y1 - Offset
'Bottom Y (Max of Top + Height of the Controls)
tmpXY(0) = Reports(Form).Controls(ULCtrl).Top + Reports(Form).Controls(ULCtrl).height
tmpXY(1) = Reports(Form).Controls(LRCtrl).Top + Reports(Form).Controls(LRCtrl).height
If (tmpXY(0) > tmpXY(1)) Then
Y2 = tmpXY(0)
Else
Y2 = tmpXY(1)
End If
Y2 = Y2 + Offset
Reports(Form).Line (X1, Y1)-(X2, Y2), LnColor, B
End Function
[code]
This one does JUST a vertical Line
Public Function BasVertLn(Form As String, MyCtrl As String, _
Optional LR As Boolean = True) As String
'Michael Red, 12/1/2001
'Draw a Vertical Line Beside a Controls on a Report
'where the control's Properties CanGrow and CanShrink may be TRUE
Dim X1 As Double 'Left
Dim Y1 As Double 'Top
Dim X2 As Double 'Right
Dim Y2 As Double 'Bottom
Dim Offset As Long 'Border / Whitspace Width
Dim LnColor As Double 'Line color to Draw
Offset = 35
'Must be CALED from OnPrint Event of Report. Similar to:
'Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
' MyCoords = basVarBox(Me.name, Expression.name, False) Lines to RIGHT
'End Sub
' -OR-
'Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
' MyCoords = basVarBox(Me.name, Expression.name, True) Lines to LEFT
'End Sub
'Where:
' MyCoords is a Dummy (String) variable
' Me.Name is a constant (returns the Name of the REPORT)
' Expression(.Name) is the "name" of the Controls.
'Left X (Min of Left of the Control)
X1 = Reports(Form).Controls(MyCtrl).Left
X1 = X1 - Offset
'Right X (Max of Left + Width of the Controls)
X2 = Reports(Form).Controls(MyCtrl).Left + Reports(Form).Controls(MyCtrl).Width
X2 = X2 + Offset
'Top Y (Min of Top of the Controls)
Y1 = Reports(Form).Controls(MyCtrl).Top
Y1 = Y1 - Offset
'Bottom Y (Max of Top + Height of the Controls)
Y2 = Reports(Form).Controls(MyCtrl).Top + Reports(Form).Controls(MyCtrl).height
Y2 = Y2 + Offset
Select Case LR
Case Is = True
Reports(Form).Line (X1, Y1)-(X1, Y2), LnColor
Case Is = False
Reports(Form).Line (X2, Y1)-(X2, Y2), LnColor
End Select
End Function
[/code] MichaelRed
m.red@att.net
There is never time to do it right but there is always time to do it over