Conditional Formatting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MNNovice
    Contributor
    • Aug 2008
    • 418

    Conditional Formatting

    I looked up the Help key to find out more about conditional formatting in Access. But all I could find is this
    Code:
    To apply conditional formatting to a control on a data access page, you need to write a VBA event procedure.
    I am trying to show certain data in different color on a report depending on a Yes/No data type. The field name is SPAP. How do I do this?

    Can someone please help? Thanks.
  • Denburt
    Recognized Expert Top Contributor
    • Mar 2007
    • 1356

    #2
    I don't remember where I got the colors from, some I use some I don't.
    Code:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    On Error Resume Next
    '10292543
    '10282543
    ' Light BlueGeen 14282543
    'LightGreen 10282643
    'Mauve 11634643
    'Light Purple 15634643
    'Light Blue 16634643
    '79102
    '16633633
    '10079102
    Const cRed As Long = 9671679
    Const cYellow As Long = 10092543
    Const cBlue As Long = 16634643
    Const cwhite As Long = 16777215
    Const cPurple As Long = 16751052
    Const cGrey As Long = 13487565
    Dim ctl As Control
    Dim sec As Section
             Set sec = Me.Section("Detail")
    If Me!SPAP= True Then
                sec.BackColor = cYellow
    Else
              sec.BackColor = cwhite 
    End If
    
    'Use the following to alrternate colors
    '         If sec.BackColor = cwhite Then
    '            sec.BackColor = cGrey
    '         Else
    '            sec.BackColor = cwhite
    '         End If

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32653

      #3
      M,

      There is no need to apply the conditional formatting programmaticall y. It can be done in the design of the form.

      Open form in Design View. Select the control and then Format / Conditional Formatting....

      From there it should be reasonably straightforward .

      Comment

      • Denburt
        Recognized Expert Top Contributor
        • Mar 2007
        • 1356

        #4
        LOL I do so much in code I forget about some of the more simple easier to use tools. Thanks NeoPa for helping to remind me that they do exist. Oh and M when he says
        Format / Conditional Formatting....
        he is referring to the format on the menu bar up top (FYI). I do think that for her report it may look better to color the whole row versus each control or a single control.

        Comment

        Working...