Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Access Report Group Borders

Status
Not open for further replies.

dmhgt3

Technical User
Sep 11, 2010
7
US
I have an Access Report with one grouping column (City). Within each City group, there may be anywhere from 1 to 5 companies. I was wondering if there is a way to put a border around each city section but not have borders between each company record.
 
The answer might depend on whether or not a company section (maybe detail) is allowed to grow or not. If sections are not allowed to grow, you could combine horizontal lines in the City group header and footer section with vertical lines in the company section.

If any of these sections can grow then you may need to use code in the On Print event of the sections that uses the Line method to draw the lines.

Duane
Hook'D on Access
MS Access MVP
 
Thanks. Right now, I am putting a horizontal line in the City header and footer and vertical lines on the left and right of the detail section. This simulates a border around every city group, but if you zoom in when previewing the report, you can tell the borders are pieced together. I believe doing it this way eliminates problems if the company section were to grow in number of records. I'm just looking for a more robust way of insert borders.
 
The most accurate method is to use the line method as I suggested. Plus it will handle sections that can grow. The following sample code assumes you have a horizontal line [ReferenceLine] in the Group Header section near the top. The width and position of the line is used as "markers" for the top of the box. Make the line invisible.

Code:
Option Compare Database
Option Explicit

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
[COLOR=#4E9A06]    ' Draw       |                                      |
    '            |                                      |
    '
    ' ReferenceLine is an invisible line in the Group Header section to pull measurements from[/color]
    
    Dim lngTop As Long, lngLeft As Long, lngRight As Long, lngWidth As Long, lngHeight As Long
    lngTop = Me.ReferenceLine.Top
    lngLeft = Me.ReferenceLine.Left
    lngWidth = Me.ReferenceLine.Width
    lngRight = lngLeft + lngWidth
    lngHeight = Me.Height
    Me.Line (lngLeft, 0)-Step(0, lngHeight)
    Me.Line (lngRight, 0)-Step(0, lngHeight)
    
End Sub

Private Sub GroupFooter1_Print(Cancel As Integer, PrintCount As Integer)
    
[COLOR=#4E9A06]    '            |                                      |
    ' draw lines |______________________________________|
    '
    ' ReferenceLine is an invisible line in the Group Header section to pull measurements from[/color]
    
    Dim lngTop As Long, lngLeft As Long, lngRight As Long, lngWidth As Long, lngHeight As Long, lngGapBetween
    lngTop = 0
    lngGapBetween = 100   [COLOR=#4E9A06]'spacing[/color]
    lngLeft = Me.ReferenceLine.Left
    lngWidth = Me.ReferenceLine.Width
    lngRight = lngLeft + lngWidth
    lngHeight = Me.Height - lngGapBetween
    Me.Line (lngLeft, lngHeight)-Step(lngWidth, 0)
    Me.Line (lngLeft, 0)-Step(0, lngHeight)
    Me.Line (lngRight, 0)-Step(0, lngHeight)
    
End Sub

Private Sub GroupHeader0_Print(Cancel As Integer, PrintCount As Integer)
[COLOR=#4E9A06]    ' draw lines  ______________________________________
    '            |                                      |
    '
    ' ReferenceLine is an invisible line in the Group Header section to pull measurements from[/color]
    
    Dim lngTop As Long, lngLeft As Long, lngRight As Long, lngWidth As Long, lngHeight As Long
    lngTop = Me.ReferenceLine.Top
    lngLeft = Me.ReferenceLine.Left
    lngWidth = Me.ReferenceLine.Width
    lngRight = lngLeft + lngWidth
    lngHeight = Me.Height
    Me.Line (lngLeft, lngTop)-Step(lngWidth, 0)
    Me.Line (lngLeft, lngTop)-Step(0, Me.Height)
    Me.Line (lngRight, lngTop)-Step(0, Me.Height)
End Sub

Duane
Hook'D on Access
MS Access MVP
 
I'm confused about what you mean by sections that could grow. The columns in the records in my detail section should always be the same height and width. Thanks for the code though. I will try this out soon.
 
Gotcha. My text boxes are set to not grow, so I should be ok.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top