Print vertical lines in the detail section of a report

I want to have 3 lines print vertically in the detail section of a report.  But they need to grow dynamically depending on the height of the detail section which has "can grow" fields in it.
The first line is to print at the very left-hand margin of the report, the 2nd line is to print 2 inches from the 1st line, and the 3rd line is to print at the very right-hand margin.  Can and how can this be done?
SteveL13Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Máté FarkasDatabase Developer and AdministratorCommented:
You should use these properties:
 - Tabular structure in your report
 - Gridlines in fields of the Detail
 - CanGrow = True property of the field
Dale FyeOwner, Developing Solutions LLCCommented:
@Mate,

the OP wants the vertical lines that are embedded in the report to grow along with the height of the detail section, so that there are no gaps in the line when viewed in print preview or printed.  Since lines don't grow (or shrink) with the textboxed displayed in a section, I tried changing the height of the line in the sections format, paint, and print events, but none of those seemed to work.
Helen FeddemaCommented:
You could do this using the old Line property of the report.  My Access Archon article on Making Variable Height Boxed Controls has some code to create boxes; you may be able to modify it to create just vertical lines.  I am attaching the zip with the article and a sample database.  Here is some of the code:

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

On Error GoTo ErrorHandler
   
   Dim sngTop As Single
   Dim sngLeft As Single
   Dim sngHeight As Single
   Dim sngWidth As Single
   
   sngHeight = Me![txtCompanyName].Height
   sngTop = Me![txtCompanyName].Top
   Me.DrawStyle = 0
   Me.DrawWidth = 3
   
   'Create box around Customer ID
   sngLeft = 0
   sngWidth = 1440
   Me.Line (sngLeft, sngTop)- _
      (sngWidth + sngLeft, sngHeight + sngTop), RGB(0, 0, 0), B

   'Create box around Company Name
   sngLeft = 1440
   sngWidth = 1440 * 2
   Me.Line (sngLeft, sngTop)- _
      (sngWidth + sngLeft, sngHeight + sngTop), RGB(0, 0, 0), B

   'Create box around Country
   sngLeft = 1440 * 3
   sngWidth = 1440
   Me.Line (sngLeft, sngTop)- _
      (sngWidth + sngLeft, sngHeight + sngTop), RGB(0, 0, 0), B
   
   'Create box around Phone
   sngLeft = 1440 * 4
   sngWidth = 1440
   Me.Line (sngLeft, sngTop)- _
      (sngWidth + sngLeft, sngHeight + sngTop), RGB(0, 0, 0), B
   
   'Create box around Fax
   sngLeft = 1440 * 5
   sngWidth = 1440
   Me.Line (sngLeft, sngTop)- _
      (sngWidth + sngLeft, sngHeight + sngTop), RGB(0, 0, 0), B
      
ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
   Resume ErrorHandlerExit

End Sub

Open in new window

accarch104.zip
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Steve,

 are you working with a pre-printed form?   If so, have a look at this:

https://www.experts-exchange.com/articles/8911/How-to-underlay-a-section-in-Microsoft-Access-Reports.html

 If not and you just want vertical lines, do it on the OnPage event, which is the last event fired before the page prints.

Private Sub Report_Page()

10        Me.DrawWidth = 12
20        Me.Line (Me.linCol1.left, lngTop)-(Me.linCol1.left, lngEnd)
30        Me.Line (Me.linCol2.left, lngTop)-(Me.linCol2.left, lngEnd)
40        Me.Line (Me.linCol3.left, lngTop)-(Me.linCol3.left, lngEnd)

End Sub
Dale FyeOwner, Developing Solutions LLCCommented:
Jim,

I've never used the Report_Page event.

Where are you getting the values for lngTop and lngEnd?

Dale
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<Where are you getting the values for lngTop and lngEnd?>>

Sorry, it's the points on the page where I want the line to start and end:

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

10        lngTop = Me.Line27.top + (Me.Line27.BorderWidth * 20)

End Sub


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

10        lngEnd = Me.top

End Sub


 In this case, it was a packing slip and I only wanted the lines between the bottom of the column headings (which was a line) and the footer.

 In the OnPage event, you can address the entire page.

Jim.
SteveL13Author Commented:
Jim,  Something isn't working.  I have this in the page footer:

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

    lngEnd1 = Me.Line25.Top
    lngEnd2 = Me.Line26.Top
    lngEnd3 = Me.Line28.Top

End Sub

Open in new window


And I have this in the page header:

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

    lngTop1 = Me.Line25.Top + (Me.Line25.BorderWidth * 20)
    lngTop2 = Me.Line26.Top + (Me.Line26.BorderWidth * 20)
    lngTop3 = Me.Line28.Top + (Me.Line28.BorderWidth * 20)

End Sub

Open in new window


And I have this in the  report page:

Private Sub Report_Page()

    Me.DrawWidth = 12
    
    Me.Line25 (Me.linCol1.Left, lngTop1)-(Me.linCol1.Left, lngEnd1)
    Me.Line26 (Me.linCol2.Left, lngTop2)-(Me.linCol2.Left, lngEnd2)
    Me.Line28 (Me.linCol3.Left, lngTop3)-(Me.linCol3.Left, lngEnd3)

End Sub

Open in new window


But in the report page I get compile error, expected = in the hyphens.
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
It's:

Me.Line (Me.linCol1.Left, lngTop1)-(Me.linCol1.Left, lngEnd1)

 and linCol1, 2, and 3 are pre-existing line controls:

Region-Capture.jpg
Jim.
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
What might be confusing is that I had horizontal lines running across the page in the header and footer.    In the On Page, I'm drawing a line on the Report using some dummy line controls to help control the placement.   You really don't need those.  It was just an easy way to do it.

 Sorry for not being clear.

Here's the help for the Line method:

Region-Capture.jpg
 
Note that what your doing in the call is specifying the x1, y1, and x2,y2 values.

Jim.
SteveL13Author Commented:
I'm very confused.  Nothing I've tried will compile.  What I want to do is have 3 lines print vertically in the detail section of a report.  But they need to grow dynamically depending on the height of the detail section which has "can grow" fields in it.
The first line is to print at the very left-hand margin of the report, the 2nd line is to print 2 inches from the 1st line, and the 3rd line is to print at the very right-hand margin.

So if you would, please let me know what code should go in the page footer. the page header, and the report page sections.
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
This BTW is what it ends up looking like:

Region-Capture.jpg
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<< What I want to do is have 3 lines print vertically in the detail section of a report. >>

1. Create three line controls called linCol1, linCol2, and linCol3  
2. Place them in the report in the page headings where you want  them across the page.

NOTE:  you do not really need these controls as all your doing is using the controls as a placement guide.     You could specify the X1 / Y1 and X2 / Y2 values directly with the line method:

  Me.Line (100,200) - (100,400)

  But then you'd need to figure out the values.   By using line controls, you can then refer to their .Left properties:

Me.Line (Me.linCol1.Left, lngTop1)

  If the controls top position was also in the right place, then I could do:

Me.Line (Me.linCol1.Left, Me.linCol1.Top)

  But what I did was to pick-up its current position and stuff it in a variable.   Likewise when I hit the page footer, I knew where the line had to stop, so I stored that position in lngEnd1.

  So what I'm doing with this:

Me.Line (Me.linCol1.Left, lngTop1)-(Me.linCol1.Left, lngEnd1)

  Is drawing a line down the page.

  Does that make more sense?   Really sorry I didn't make that clear right off.   I had forgotten I used this little trick for some of the positioning.

Jim.
SteveL13Author Commented:
Not making sense yet.  I don't know what to put where.  Sorry.
Dale FyeOwner, Developing Solutions LLCCommented:
Steve,

Just try this to start with:

me.line (.25*1440, 1)-(.25 * 1440, 10 * 1440)

This should create a line on your form, .25" in from the left, 1" from the top down through 10" from the top.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteveL13Author Commented:
I got it with:

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

    Me.DrawWidth = 10

    Me.Line (0.01 * 1440, 0)-(0 * 1440, 10 * 1440)
    Me.Line (1.9583 * 1440, 0)-(1.9583 * 1440, 10 * 1440)
    Me.Line (7.99 * 1440, 0)-(8 * 1440, 10 * 1440)

End Sub

Open in new window


I had to "cheat" with the 0.01 and 7.99 in order for them to show up.
SteveL13Author Commented:
Thanks to all who helped.  All very useful information.
Dale FyeOwner, Developing Solutions LLCCommented:
Thanks for the points, but I would have given Jim most of the points.  I don't have a problem if you want to open up the question and re-award points.

I was happy he posted about the Line method, because I had never used it before.  I still have not figured out how to use it to just span the detail section, but knowing how to draw the lines for specific start and end point on the page works for me, for now.

Dale
SteveL13Author Commented:
Sorry, again, how do I re-open a question?
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<Sorry, again, how do I re-open a question?>>

 Don't bother.   I'm not here for the points.

Jim.
SteveL13Author Commented:
I appreciate that, Jim.  But I do want to be fair.
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Like I said, don't worry about it.  dale did a better job of it getting you to understand, and in the end, that's what you used to solve your problem.

So I think the points are fine.

Jim.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.