Results 1 to 7 of 7
  1. #1
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    This is Access 2007.

    I want to set the backcolor of certain controls on a subreport to various colours based upon a value of the control.

    I want to set the baclcolor to white of all controls except where:
    a control is Null i want to show the backcolor as Red, or,
    a particular control passes another test i wish to make the backcolor green.

    The OnFormat event is:
    [pre]
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    On Error Resume Next

    Const cYellow As Long = 10092543
    Const cWhite As Long = 16777215
    Const cPurple As Long = 16751052
    Dim ctl As Control
    Dim sec As Section
    Set sec = Me.Section("Detail")

    For Each ctl In sec.Controls
    If Left(ctl.Name, 2) = "dc" Then
    If IsNull(ctl) Then
    ctl.BackColor = vbRed
    Else
    If Right(Me(RptFieldname), 1) = "1" Then
    ' set the lowest price to green
    ctl.BackColor = cYellow ' vbGreen
    Else
    ctl.BackColor = cWhite ' vbWhite
    End If
    End If
    End If
    Next

    End Sub
    [/pre]

    It doesn't seem to even go thru this code as i have put a Stop command and it doesn't stop.

    Any ideas?

    There is only one page printed and it is 124 lines long? This seems strange?

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    What happens when you step through the code?

    What does this line mean?

    Code:
    If Right(Me(RptFieldname), 1) = "1" Then
    When I removed that the code ran, and did something for me.
    Regards
    John



  3. #3
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    As i said it doesn't even go thru the code

    That is a test to signal the lowest cost so i can show another colour.

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Code:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    msgbox "Here"
    On Error Resume Next
    If you put a message box here do you see it?

    Is the On Error Resume Next hiding some error?

    I can see that
    Code:
    If Right(Me(RptFieldname), 1) = "1" Then
    is designed to test something, I just don't understand the syntax.
    Regards
    John



  5. #5
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    Dont worry i was using the Report View rather than the Print Preview button.

    As regards that test i have to revise that.

  6. #6
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    My report now executes the Format event of the detail section, but its not changing the BackColor of controls.
    The code is:
    [pre]
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    On Error Resume Next

    Const cYellow As Long = 10092543
    Const cWhite As Long = 16777215
    Const cPurple As Long = 16751052
    Dim ctl As Control
    Dim sec As Section
    Set sec = Me.Section("Detail")
    'Stop
    For Each ctl In sec.Controls
    If Left(ctl.Name, 3) = "Sup" Then
    If IsNull(ctl) Then
    ctl.BackColor = vbRed
    Else

    If Me!RptFieldname = ctl.Name Then
    ' set the lowest price to green
    ctl.BackColor = vbGreen
    Else
    ctl.BackColor = vbWhite
    End If
    End If
    End If
    Next

    End Sub
    [/pre]

    Can anyone see any problems?

  7. #7
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    All solved.

    Ths BackStyle as transparent, as soon as i changed that to normal it worked just fine.

Posting Permissions

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