Results 1 to 5 of 5
  1. #1
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    192

    Report Format Event

    Dear Experts,

    The following code on the Report's Format Event shows Runtime Error 438:

    The Report is based on a Cross Tab Query which has to show different back colors for individual rows. I got this code from a You Tube tutorials.

    Option Explicit

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Dim ctl As Control

    Select Case True


    Case Me.RowCounter Mod 2 = 0 'white

    For Each ctl In Me.Detail.Controls
    If ctl.Tag = "orange" Then
    ctl.BackColor = RGB(255, 255, 255)
    ElseIf ctl.Tag = "blue" Then
    ctl.BackColor = RGB(245, 250, 250)
    End If

    Next ctl
    Case Me.RowCounter Mod 4 = 1 'medium

    For Each ctl In Me.Detail.Controls
    If ctl.Tag = "orange" Then
    ctl.BackColor = RGB(250, 200, 170)
    ElseIf ctl.Tag = "blue" Then
    ctl.BackColor = RGB(168, 216, 224)
    End If

    Next ctl
    Case Else 'light

    For Each ctl In Me.Detail.Controls
    If ctl.Tag = "orange" Then
    ctl.BackColor = RGB(255, 232, 218)
    ElseIf ctl.Tag = "blue" Then
    ctl.BackColor = RGB(200, 230, 230)
    End If

    Next ctl
    End Select

    For Each ctl In Me.Detail.Controls
    If ctl.Value >= 10000 Then
    ctl.ForeColor = RGB(255, 0, 0)
    ctl.FontBold = True
    Else
    ctl.ForeColor = RGB(0, 0, 0)
    ctl.FontBold = False
    End If

    Next ctl
    End Sub

    Please check what is wrong in the code.

    Regards
    Alex

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    Your last FOR (outside the SELECT) overrides everything you did before...
    "For Each ctl In Me.Detail.Controls"
    " If ctl.Value >= 10000 Then


    you should also indent

    Code:
    Select Case True
        Case Me.RowCounter Mod 2 = 0    'white
            For Each ctl In Me.Detail.Controls
                If ctl.Tag = "orange" Then
                   ctl.BackColor = RGB(255, 255, 255)
                ElseIf ctl.Tag = "blue" Then
                   ctl.BackColor = RGB(245, 250, 250)
                End If
            Next ctl
            
        Case Me.RowCounter Mod 4 = 1      'medium
            For Each ctl In Me.Detail.Controls
                If ctl.Tag = "orange" Then
                    ctl.BackColor = RGB(250, 200, 170)
                ElseIf ctl.Tag = "blue" Then
                    ctl.BackColor = RGB(168, 216, 224)
                End If
            Next ctl
        
        Case Else    'light
            For Each ctl In Me.Detail.Controls
                If ctl.Tag = "orange" Then
                    ctl.BackColor = RGB(255, 232, 218)
                ElseIf ctl.Tag = "blue" Then
                    ctl.BackColor = RGB(200, 230, 230)
                End If
            Next ctl
    End Select
        
    For Each ctl In Me.Detail.Controls
            If ctl.Value >= 10000 Then
                ctl.ForeColor = RGB(255, 0, 0)
                ctl.FontBold = True
            Else
                ctl.ForeColor = RGB(0, 0, 0)
                ctl.FontBold = False
            End If
    Next ctl

  3. #3
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    192
    Thank you ranman256,
    Can you please re frame the code for me?
    Alex

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    Did you consider textbox Conditional Formatting instead of VBA code? Could probably use an UNBOUND textbox with Conditional Formatting behind other controls to allow for 'row' coloring. Set labels and other textboxes as transparent.

    Which line throws the error? Step debug. Refer to link at bottom of my post for debugging guidelines.

    Possibly the issue is the code looks at EVERY control - labels, textboxes, lines, subreport containers, etc. Some of these controls do not have Value property. So you need more conditional code in that last For structure that restricts to only those controls that have Value property. On a report, these would usually be just textboxes - no comboboxes or listboxes or checkboxes, etc.

    Also, on second thought, some controls don't have backcolor - such as line.

    Why are some controls tagged for orange and some for blue - what was the determining factor?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    192
    Thanks for the response.
    I solved the problem by removing the last bloc and made conditional formatting.
    Alex

Please reply to this thread with any new information or opinions.

Similar Threads

  1. On Load Event for report
    By zburns in forum Programming
    Replies: 10
    Last Post: 05-12-2015, 12:38 PM
  2. Using Format in On Click Event fails
    By Middlemarch in forum Programming
    Replies: 10
    Last Post: 03-24-2015, 11:03 PM
  3. Event program as MS Access report
    By ltech78 in forum Reports
    Replies: 1
    Last Post: 05-31-2014, 11:03 AM
  4. Replies: 4
    Last Post: 08-28-2013, 05:20 PM
  5. Triggering a form event from a report
    By Paul H in forum Forms
    Replies: 2
    Last Post: 10-12-2012, 09:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums