Conditional Formatting ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tulikapuri
    New Member
    • Feb 2007
    • 55

    Conditional Formatting ?

    Can someone please guide me an easy way of having more than three conditional formatting conditions?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by tulikapuri
    Can someone please guide me an easy way of having more than three conditional formatting conditions?
    I'm afraid that you will have to take the code route for that. Here is a simple example based on a Postal Code Field (txtPostalCode) on a Form:
    Code:
    Private Sub Form_Current()
    Select Case Me![txtPostalCode]
      Case 98105
        Me![txtPostalCode].ForeColor = QBColor(2)
        Me![txtPostalCode].FontBold = True
        Me![txtPostalCode].FontUnderline = False
      Case 98122
        Me![txtPostalCode].ForeColor = vbBlue
        Me![txtPostalCode].FontBold = False
        Me![txtPostalCode].FontUnderline = True
      Case 98401
        Me![txtPostalCode].ForeColor = QBColor(4)
        Me![txtPostalCode].FontBold = True
        Me![txtPostalCode].FontUnderline = False
      Case 98033
        Me![txtPostalCode].ForeColor = QBColor(3)
        Me![txtPostalCode].FontBold = True
        Me![txtPostalCode].FontUnderline = False
      Case Else
        Me![txtPostalCode].ForeColor = 0
        Me![txtPostalCode].FontBold = False
        Me![txtPostalCode].FontUnderline = False
    End Select
    End Sub

    Comment

    • tulikapuri
      New Member
      • Feb 2007
      • 55

      #3
      Originally posted by ADezii
      I'm afraid that you will have to take the code route for that. Here is a simple example based on a Postal Code Field (txtPostalCode) on a Form:
      Code:
      Private Sub Form_Current()
      Select Case Me![txtPostalCode]
        Case 98105
          Me![txtPostalCode].ForeColor = QBColor(2)
          Me![txtPostalCode].FontBold = True
          Me![txtPostalCode].FontUnderline = False
        Case 98122
          Me![txtPostalCode].ForeColor = vbBlue
          Me![txtPostalCode].FontBold = False
          Me![txtPostalCode].FontUnderline = True
        Case 98401
          Me![txtPostalCode].ForeColor = QBColor(4)
          Me![txtPostalCode].FontBold = True
          Me![txtPostalCode].FontUnderline = False
        Case 98033
          Me![txtPostalCode].ForeColor = QBColor(3)
          Me![txtPostalCode].FontBold = True
          Me![txtPostalCode].FontUnderline = False
        Case Else
          Me![txtPostalCode].ForeColor = 0
          Me![txtPostalCode].FontBold = False
          Me![txtPostalCode].FontUnderline = False
      End Select
      End Sub
      How do i get here, and how & where to write a code ?

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by tulikapuri
        How do i get here, and how & where to write a code ?
        The code would be written in the Form's Current() Event as indicated so that it may reflect different States for each Record.
        Last edited by ADezii; Apr 16 '07, 06:50 PM. Reason: Typographical Error

        Comment

        • tulikapuri
          New Member
          • Feb 2007
          • 55

          #5
          Originally posted by ADezii
          The code would be written in the Form's Current() Event as indicated so that it may reflect different States for each Record.
          I am trying to do the conditional formatting in a report where i have added some other sub reports aswell, so how do i write the code for tht now?

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Originally posted by tulikapuri
            I am trying to do the conditional formatting in a report where i have added some other sub reports aswell, so how do i write the code for tht now?
            In the Report's Detail Section, Format() Event as in:
            Code:
            Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
            Select Case Me![Title]
              Case "Sir"
                Me![Title].FontWeight = Bold
                Me![Title].FontSize = 12
                Me![Title].FontUnderline = False
                Me![Title].BorderStyle = 1
              Case "Mr."
                Me![Title].FontWeight = Bold
                Me![Title].FontSize = 10
                Me![Title].FontUnderline = True
                Me![Title].BorderStyle = 0
              Case "Dude"
                Me![Title].FontWeight = Normal
                Me![Title].FontSize = 12
                Me![Title].FontUnderline = True
                Me![Title].BorderStyle = 0
              Case Else
                Me![Title].FontWeight = Normal
                Me![Title].FontSize = 8
                Me![Title].FontUnderline = False
                Me![Title].BorderStyle = 0
            End Select

            Comment

            • tulikapuri
              New Member
              • Feb 2007
              • 55

              #7
              Can you please tell in more detail as to how can i get it done, actually i am new to access DB and dont know a lot of stuff.

              I tried as desribed in your last post but i could not find the format () Event in report's detail section.

              Thanks,

              Comment

              • ADezii
                Recognized Expert Expert
                • Apr 2006
                • 8834

                #8
                Originally posted by tulikapuri
                Can you please tell in more detail as to how can i get it done, actually i am new to access DB and dont know a lot of stuff.

                I tried as desribed in your last post but i could not find the format () Event in report's detail section.

                Thanks,
                1. Select your Report inh the Database Window
                2. Click on Design
                3. Double Click on the Detail Section (between Page Header and Page Footer)
                4. Click on Format
                5. Click on the Build (...) button
                6. Select Code builder
                7. Click on OK
                8. Copy and Paste the code in this Event (Format())

                Comment

                • tulikapuri
                  New Member
                  • Feb 2007
                  • 55

                  #9
                  Thanks i got it right till here, but now since i have report with sub reports and each field had conditional formatting ,

                  First of all, can i look at the code for the three conditions i wrote , so that i get an e.g. of how to build the code.

                  Secondly, how do i do the conditional formatting for each and every single field?

                  For e.g. I have moisture values which should be green if its in the range 2.35 - 3.25 and then yellow if its less than 2.35 - 2.10 and yellow again if it is greater than 3.25-3.50. And red if it is less than 2.10 and greater than 3.5.

                  Comment

                  • ADezii
                    Recognized Expert Expert
                    • Apr 2006
                    • 8834

                    #10
                    Originally posted by tulikapuri
                    Thanks i got it right till here, but now since i have report with sub reports and each field had conditional formatting ,

                    First of all, can i look at the code for the three conditions i wrote , so that i get an e.g. of how to build the code.

                    Secondly, how do i do the conditional formatting for each and every single field?

                    For e.g. I have moisture values which should be green if its in the range 2.35 - 3.25 and then yellow if its less than 2.35 - 2.10 and yellow again if it is greater than 3.25-3.50. And red if it is less than 2.10 and greater than 3.5.
                    Here is a Code Templqate:
                    Code:
                    Select Case Me![txtRange]
                      Case Is > 3.5
                         Me![txtMoisture Values].ForeColor = vbRed
                      Case 2.35 To 3.5
                         Me![txtMoisture Values].ForeColor = vbGreen
                      Case 2.10 To 2.34
                         Me![txtMoisture Values].ForeColor = vbYellow
                      Case Is < 2.1
                         Me![txtMoisture Values].ForeColor = vbRed
                      Case Else
                         Me![txtMoisture Values].ForeColor = vbBlack
                    End Select

                    Comment

                    • tulikapuri
                      New Member
                      • Feb 2007
                      • 55

                      #11
                      Originally posted by ADezii
                      Here is a Code Templqate:
                      Code:
                      Select Case Me![txtRange]
                        Case Is > 3.5
                           Me![txtMoisture Values].ForeColor = vbRed
                        Case 2.35 To 3.5
                           Me![txtMoisture Values].ForeColor = vbGreen
                        Case 2.10 To 2.34
                           Me![txtMoisture Values].ForeColor = vbYellow
                        Case Is < 2.1
                           Me![txtMoisture Values].ForeColor = vbRed
                        Case Else
                           Me![txtMoisture Values].ForeColor = vbBlack
                      End Select
                      How do i enter this format now, i opened the detail column and it doesnt show me correctly the build property, since i have seven different fields like moisture, temperature, GS, Compactibility etc. and all have different values, so what should i do now??

                      Comment

                      • tulikapuri
                        New Member
                        • Feb 2007
                        • 55

                        #12
                        I could do this successfully but its asking me for the txtrange, what should i enter here?

                        Comment

                        • tulikapuri
                          New Member
                          • Feb 2007
                          • 55

                          #13
                          it gives me runtime error '2465' that it cant determine the txtrange?

                          Comment

                          Working...