Allow Vertical Lines to Grow with Other Fields (1 Viewer)

DoneganF

Registered User.
Local time
Yesterday, 22:35
Joined
Aug 7, 2012
Messages
29
I have a report in which I use vertical lines to separate values. However, there are data fields which need to grow, while others do not (some data fields require two lines while other only need one). Since that caused the lines to break where two rows were required, I added the code below to fix the problem. Here's the problem ... it only works when printed (or print-previewed). I need to distributed these reports in a PDF format, and this code does not work in that format. I'm thinking the existing code just needs some modifications, but I don't know where to start.

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

Dim CtlDetail As Control
Dim intLineMargin As Integer

intLineMargin = 0

For Each CtlDetail In Me.Section(asDetail).Controls
With CtlDetail
If CtlDetail.Name = "Line155" Then
Me.Line ((.Left + .Width + intLineMargin), 0)-(.Left + .Width + _
intLineMargin, Me.Height)
End If
End With

Next
Set CtlDetail = Nothing

End Sub
 

Minty

AWF VIP
Local time
Today, 06:35
Joined
Jul 26, 2013
Messages
10,371
When printed to PDF the OnFormat or OnPrint events should fire. They don't for report view but the print preview is exactly what should happen when you print to pdf.

How are you printing to pdf, or are you exporting?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:35
Joined
May 7, 2009
Messages
19,247
i think the format for Line function is:

Me.Line(x, y)-Step(theWidthOfLine, theHeightOfLine), lngColor [, optional FillColor if rectangle]
 

DoneganF

Registered User.
Local time
Yesterday, 22:35
Joined
Aug 7, 2012
Messages
29
I am exporting the PDF files and emailing them to report recipients.
 

Minty

AWF VIP
Local time
Today, 06:35
Joined
Jul 26, 2013
Messages
10,371
What's the code you are using ?
Print to pdf as a file then attach to the email should work.
 

Mark_

Longboard on the internet
Local time
Yesterday, 22:35
Joined
Sep 12, 2017
Messages
2,111
For the code sample, you are looping through all controls. Are you doing anything with any control OTHER than line155? If not, why loop through all of the controls?

P.S. I'd really suggest giving your controls a better name. Line155 has about as much meaning as Txt12...
 

MarkK

bit cruncher
Local time
Yesterday, 22:35
Joined
Mar 17, 2004
Messages
8,186
It looks like in your code you are confusing an Access.Line control with the Access.Report.Line method. The Access.Line is a control and you will not be able to move it or change it's size during the print event. The Report.Line method, by contrast, is available during Print and Page and you can draw a line anywhere on the page as a graphic.
Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
   Dim CtlDetail As Control
   Dim intLineMargin As Integer

   intLineMargin = 0

   For Each CtlDetail In Me.Section(asDetail).Controls
      With CtlDetail
         If CtlDetail.Name = "Line155" Then [COLOR="Green"]'this, Line155, is a line control[/COLOR]
[COLOR="green"]            'this method draws a line on the report independent of any control[/COLOR]
            Me.Line ((.Left + .Width + intLineMargin), 0)-(.Left + .Width + intLineMargin, Me.Height)
         End If
      End With
   Next
End Sub
Also, the Report.Section.Height property will always report the height of the section as it is in design view, but any control set to CanGrow = True will report it's True height in the Print event.

So, here's code that draws a diagonal line across a control in Detail_Print...
Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
[COLOR="Green"]    'draw a diagonal line across the control Text0
    'proving that we can detect its final height and width
    'after it is sized.
[/COLOR]    Me.ScaleMode = 1 [COLOR="green"]   'twips[/COLOR]
    Me.Line (Me.Text0.Top, Me.Text0.Left)-(Me.Text0.Width, Me.Text0.Height)
End Sub
Note that this line is not a control that is present in design view. This is a graphic, printed on the page after the controls are rendered.
hth
Mark
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:35
Joined
May 7, 2009
Messages
19,247
It is obvious that he is not using the line control to draw the line but rather a reference point where to draw the Line method.
 

Users who are viewing this thread

Top Bottom