Access 2013 – How to draw a vertical margin line when fields can grow

In access 2013 you can use a ‘line’ object to draw horizontal or vertical lines.

Typically you would draw a horizontal line through the ‘detail’ section to create a margin line between two fields.

However when you configure a field so it can grow if it contains more than a single line of text, these margin lines break and do not draw a consistent line through the detail section.

Access2013-VerticalMargin1

The steps below show how to make the ‘line’ object draw a continuous vertical line when a detail row has expanded due to a field growing.

  1. With your Access database open, open the navigation pane (on the left hand of the window) and then click on the arrow at the top and select ‘All Access Objects’
  2. Access2013-GrowReportField2
  3. Then right-click on the report you need to change the field in and select ‘Design View’
  4. Access2013-GrowReportField3
  5. If you do not already have a line object, add one in by selecting the ‘DESIGN’ menu option, then under ‘Controls’ clicking on the line and placing it in your report
  6. Access2013-VerticalMargin2
  7. Click on the line object in the report.
  8. In the right side of the window you should see the ‘Property Sheet’. If you do not have the property sheet displayed, click on the ‘Property Sheet’ button which can be found under the ‘Design’ ribbon menu in the top of the screen.
  9. Take note of the name of the line object, in this example it is line83
  10. Access2013-VerticalMargin3
  11. Now click on the ‘View Code’ button, this can be found under the ‘Design’ ribbon menu in the top of the screen.
  12. In the window that opens, paste in the following code – making sure to replace line83 with the name of your line object from step 9.
  13. 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(acDetail).Controls
        With CtlDetail
            If CtlDetail.Name = "line83" Then
            Me.Line ((.Left + .Width + intLineMargin), 0)-(.Left + .Width + _
    intLineMargin, Me.Height)
            End If
        End With
    Next
    Set CtlDetail = Nothing
    End Sub
  14. Access2013-VerticalMargin4
  15. Close the code editor and run your report.
  16. The line will now grow as fields grow.
  17. Access2013-VerticalMargin5
  18. Don’t forget to save the changes!