Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Location
    San Diego
    Posts
    45

    Question Unanswered: Access report with "graybar" features

    Hello,

    I am trying to format the report to print similar to a graybar report, but with the color changing only when a certain column's data changes. And to complicate things a bit, I have a subreport within the main report. So, the resulting report would look something like this:

    Code:
    33556622   subreportdata    data from main report <grey>                 
                     subreportdata                                     <grey> 
                     subreportdata                                     <grey>
    3355825     subreportdata    data from main report <white>
                     subreportdata                                     <white>  
                     subreportdata                                     <white>
                     subreportdata                                     <white>
    
    etc...

    I tried a procedure I found, which changed every other line to grey, and that worked fine when I put it within the subreport and the main report. However, my code is not doing a darn thing. I am wondering if there is a way to use the code I found online to do this.

    Here is my code(this is abbreviated for space reasons, as there are a lot of field names)
    Code:
    Private m_intCounter As Integer
    Private m_strPrevWPC As String
    
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    On Error GoTo Err_Detail_Format
    
    Const GREY As Long = 13553358
    
        'Increment counter only if record is a different txtWP from the previous textWP.
        If m_strPrevWPC <> txtWP Then m_intCounter = m_intCounter + 1
        
            'Set greybar
            'Greybar is Grey on even counts (counts based on change of WPC)
            If m_intCounter Mod 2 = 0 Then
                txtBlock.BackColor = GREY
                txtZONE.BackColor = GREY
                txtWP.BackColor = GREY
                txtPLN_S.BackColor = GREY
                txtPLN_C.BackColor = GREY
                
            Else 'Odd counts are normal back color
                txtBlock.BackColor = vbWhite
                txtZONE.BackColor = vbWhite
                txtWP.BackColor = vbWhite
                txtPLN_S.BackColor = vbWhite
                txtPLN_C.BackColor = vbWhite
                PCT_C.BackColor = vbWhite
                
            End If
            
        
        m_strPrevWPC = txtWP
        
    Err_Detail_Format:
        If Err <> 0 Then MsgBox Err.Number & ":  " & Err.Description
        
    End Sub


    And here is the code that I found on the web:
    Code:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    
        'Michael Red.   2/13/2002.      To 'Toggle the backolor, which
        'Provides alternate line shading
        Const XorToggle = 4144959
    
        Me.Detail.BackColor = Me.Detail.BackColor Xor XorToggle
    
    
    End Sub


    Any thoughts are greatly appreciated!

    Laurel

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    For starters, I would set all of your controls to a transparent background, there's no reason to manually set the background for them every single time you change the color, but keeping them transparent, you longer have to.

    I don't see a reason to use another control variable either, as your background is going to be one of two colors. Try something like:
    Code:
    If Me.Detail.BackColor = RGB(0,0,0) Then
       Me.Detail.BackColor = RGB(128, 128, 128)
    Else
       Me.Detail.BackColor = RGB(0,0,0)
    End If
    This code would need to be placed in the event handlers of BOTH reports.

    Also note that the code has to be placed in a header section of the subreport, as you want to alternate the background only once per key.

  3. #3
    Join Date
    Mar 2004
    Location
    San Diego
    Posts
    45
    Here is how I did it:

    within the main report's detail format procedure:
    Code:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    On Error GoTo Err_Detail_Format
    
    Const GREY As Long = 13553358
        'Increment counter only if record is a different txtWP from the previous textWP.
            If m_strPrevWPC <> txtWP Then m_intCounter = m_intCounter + 1
            'Set greybar
            'Greybar is Grey on even counts (counts based on change of WPC)
            If m_intCounter Mod 2 = 0 Then
                Me.Detail.BackColor = GREY
            Else 'Odd counts are normal back color
                Me.Detail.BackColor = vbWhite
            End If
        m_strPrevWPC = txtWP
        
    Err_Detail_Format:
        If Err <> 0 Then MsgBox Err.Number & ":  " & Err.Description
        
    End Sub
    and then within the subreport's procedure:
    Code:
    Me.Detail.BackColor = [Reports]![rptDispatch_Pkgs].Detail.BackColor

    Sometimes I make things WAY harder than necessary.


    Thanks for your response!

    LL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •