Results 1 to 15 of 15
  1. #1
    Bnecrush1 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2021
    Posts
    6

    Conditional Formatting

    I have a report that I need to do some conditional formatting on. The formatting needs to be based off of two fields.

    The first field is a type, the second is a number.
    The Type field has three choices C, T, V
    The number is between 0 and 100


    If [Type] = C and [Number] is <30 [Number] highlighted red
    If [Type] = C and [Number] is >30 And <50 [Number] Highlighted Yellow


    If [Type] = C and [Number] is >50 [Number] Highlighted Green
    If [Type] = T and [Number] is <10 [Number] highlighted red
    If [Type] = T and [Number] is >10 And <30 [Number] Highlighted Yellow
    If [Type] = T and [Number] is >30 [Number] Highlighted Green
    If [Type] = V and [Number] is <40 [Number] highlighted red
    If [Type] = V and [Number] is >40 And <70 [Number] Highlighted Yellow
    If [Type] = V and [Number] is >70 [Number] Highlighted Green


    What is the best way to do this?

    THANKS!!

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    With all that, I'd write a function to do it.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Bnecrush1 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2021
    Posts
    6
    Something along this:?

    Private Sub Form_Current()

    If Floor_Type = Concrete And AccessTotalsAoMR < 15 Then
    Floor_Type.BackColor = vbRed


    Else

    If Floor_Type = Concrete And AccessTotalsAoMR < 15 And > 30Then
    Floor_Type.BackColor = vbYellow

    Else
    If Floor_Type = Concrete And AccessTotalsAoMR > 30 Then
    Floor_Type.BackColor = vbGreen

    Else
    If Floor_Type = VCT And AccessTotalsAoMR < 60 Then
    Floor_Type.BackColor = vbRed

    Else
    If Floor_Type = VCT And AccessTotalsAoMR > 61 And < 80 Then
    Floor_Type.BackColor = vbYellow

    Else
    If Floor_Type = VCT And AccessTotalsAoMR > 80 Then
    Floor_Type.BackColor = vbGreen

    Else

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    I'd probably use nested Case statements. If you are checking strings you need to surround with "
    I'd probably set some variables ColourMin, and ColourMax for each Type then compare for the colour.

    You also have gaps in your logic with the ranges?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Agree with gasman. Hate those nested IF-THEN-ENDIF. Try this:

    Code:
    Select Case Floor_Type
        Case "Concrete"
            Select Case AccessTotalsAoMR
                Case < 15
                    Floor_Type.Backcolor = vbRed
                Case > 30
                    Floor_Type.Backcolor= vbGreen
                Case Else
                    Floor_Type.Backcolor=vbYellow
            End Select
        Case "VCT"    
            Select Case AccessTotalsAoMR
                Case < 60
                    Floor_Type.Backcolor = vbRed
                Case > 80
                    Floor_Type.Backcolor = vbGreen
                Case Else
                    Floor_Type.Backcolor = vbYellow
            End Select
    End Select
    You might need to adjust the comparators to be >= or <=
    or maybe change the numeric literals up or down by 1 to get the results you want.

    EDIT: Reading your posts again, it's not clear about Floor_Type values.
    If you need to account for additional Types, you can easily add another Select Case ... End Select to include them.
    Last edited by davegri; 02-04-2021 at 12:50 PM. Reason: See EDIT

  6. #6
    Bnecrush1 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2021
    Posts
    6
    Gave it a try and it didn't see to work - must be I have missed somthing?

    Code:
    Private Sub Form_Current()
    Select Case Floor_Type
        Case "Concrete"
            Select Case AoMR
                Case Is < 15
                    AoMR.BackColor = vbRed
                Case Is >= 30
                    AoMR.BackColor = vbGreen
                Case Else
                    AoMR.BackColor = vbYellow
            End Select
        Case "VCT"
            Select Case AoMR
                Case Is < 60
                    AoMR.BackColor = vbRed
                Case Is >= 80
                    AoMR.BackColor = vbGreen
                Case Else
                    AoMR.BackColor = vbYellow
            End Select
    
    
        Case "ConcreteS"
            Select Case AoMR
                Case Is < 50
                    AoMR.BackColor = vbRed
                Case Is >= 70
                    AoMR.BackColor = vbGreen
                Case Else
                    AoMR.BackColor = vbYellow
            End Select
    
    
        Case "Ceramic Tile"
            Select Case AoMR
                Case Is < 50
                    AoMR.BackColor = vbRed
                Case Is >= 70
                    AoMR.BackColor = vbGreen
                Case Else
                    AoMR.BackColor = vbYellow
    
    
    
    
        End Select
    
    
    
    
    End Sub

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    At least an End Select ?

    I doubt that will even compile?

    Walk through the code line by line with F8 and see what it does.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Need another END SELECT just before END SUB.
    You have the possible values of Floor_Type as

    "Concrete"
    "ConcreteS"
    "VCT"
    "Ceramic Tile"

    Is that correct?

  9. #9
    Bnecrush1 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2021
    Posts
    6
    That is correct.

    I added the END SELECT and it still didn't work.
    Currently some of the Floor_Type entries are blank. That will not be in the future - could that be causing an issue?
    Actually had it remove all the data once from the form itself after I changed the view.

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    You said in the original post that you wanted to format a report?

    Yet you are creating code in a form Current event?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #11
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Quote Originally Posted by Bnecrush1 View Post
    That is correct.

    I added the END SELECT and it still didn't work.
    Currently some of the Floor_Type entries are blank. That will not be in the future - could that be causing an issue?
    Actually had it remove all the data once from the form itself after I changed the view.
    I think your best bet is to upload the DB here so that someone can take a look. Then instead of suggested possible fixes based on speculation, you will get solid advice.

  12. #12
    Bnecrush1 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2021
    Posts
    6
    My Bad: It is a report:

    Code:
    Private Sub Report_Current()
    
    
    Select Case Floor_Type
        Case "Concrete"
            Select Case AoMR
                Case Is < 15
                    AoMR.BackColor = vbRed
                Case Is >= 30
                    AoMR.BackColor = vbGreen
                Case Else
                    AoMR.BackColor = vbYellow
            End Select
            
        Case "VCT"
            Select Case AoMR
                Case Is < 60
                    AoMR.BackColor = vbRed
                Case Is >= 80
                    AoMR.BackColor = vbGreen
                Case Else
                    AoMR.BackColor = vbYellow
            End Select
    
    
        Case "ConcreteS"
            Select Case AoMR
                Case Is < 50
                    AoMR.BackColor = vbRed
                Case Is >= 70
                    AoMR.BackColor = vbGreen
                Case Else
                    AoMR.BackColor = vbYellow
            End Select
    
    
        Case "Ceramic Tile"
            Select Case AoMR
                Case Is < 50
                    AoMR.BackColor = vbRed
                Case Is >= 70
                    AoMR.BackColor = vbGreen
                Case Else
                    AoMR.BackColor = vbYellow
            End Select
         
            
    End Select
    
    
    
    
    
    
    End Sub

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    I would hazard a guess that the code needs to be in the Detail On Format event?

    Code:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  14. #14
    Bnecrush1 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2021
    Posts
    6
    Thanks everyone - got it to work on the "On Load"

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    Quote Originally Posted by Bnecrush1 View Post
    Thanks everyone - got it to work on the "On Load"
    That event only happens once?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. conditional formatting
    By mannyy12 in forum Access
    Replies: 21
    Last Post: 04-05-2020, 10:17 AM
  2. Replies: 2
    Last Post: 11-12-2015, 10:46 AM
  3. Need Help With Conditional Formatting
    By Ursa2312 in forum Access
    Replies: 3
    Last Post: 07-28-2015, 11:18 AM
  4. Replies: 6
    Last Post: 05-26-2013, 09:10 PM
  5. Conditional formatting
    By avarusbrightfyre in forum Forms
    Replies: 3
    Last Post: 07-01-2011, 11:18 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