Demo of Conditional format in subform - Unlimited colours

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mshmyob
    Recognized Expert Contributor
    • Jan 2008
    • 903

    Demo of Conditional format in subform - Unlimited colours

    This demo is a simple way to change the colours in a subform to highlite different conditions.

    Access only allows a maximum of 4 conditional changes to individual controls but with this simple trick you can apply thousands of colour changes to any number of controls or even entire rows in a subform set to continuous forms.

    Note: This works only in AC2007 I believe. Since I notice more and more AC2007 questions and always see questions about conditional formatting I decided to throw this together for the community.

    If you have any questions please feel free to ask.

    cheers
    Attached Files
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32662

    #2
    I've moved this across to the Insights area (as well as noted so I can direct people here when required).

    Comment

    • FishVal
      Recognized Expert Specialist
      • Jun 2007
      • 2656

      #3
      I don't have Access 2007, but still curious to know what method was applied to achieve the goal. Could you please describe the basics of your approach? Sure, not full how-to-do instructions - just few words about the main idea of the method.

      Regards,
      Fish.

      Comment

      • mshmyob
        Recognized Expert Contributor
        • Jan 2008
        • 903

        #4
        Sure Fish.

        Actually was quite easy to accomplish with AC2007.

        The tables used in demo consisted of a Vendor Table and Product Table.

        Main form for Vendor - subform Products.

        DataSource for Subform

        [code=vb]
        SELECT tblVendor.Vendo rID, tblProduct.Prod uctID, tblProduct.Prod uctDesc, tblProduct.Prod Price, fProdPriceCondi tion(ProdPrice) AS PriceConditiona l FROM tblVendor INNER JOIN tblProduct ON tblVendor.Vendo rID=tblProduct. VendorID WHERE tblProduct.Vend orID=Forms![frmColumnCondit ional].txtVendorID;
        [/code]


        Module Code

        [code=vb]
        Public Function fProdPriceCondi tion(dblPrice As Double)

        'this function is used to determine the background colour for the product price
        ' this is an example of how to change the colour of a single control on each row of a subform
        ' if under $10 1st conditional, 11 to 15 condition 2, 16 to 20 condition 3, 21 to 25 condition 4, 26 to 30 condition 5

        Dim strDatabasePath As String

        ' get the path where the bitmaps are stored
        strDatabasePath = CurrentProject. Path

        ' change background colour of text price control (really changing an image control behind the text price control based on the value in the price field
        Select Case dblPrice
        Case Is <= 10
        fProdPriceCondi tion = strDatabasePath & "\red_price.bmp "
        Case Is <= 15
        fProdPriceCondi tion = strDatabasePath & "\pink_price.bm p"
        Case Is <= 20
        fProdPriceCondi tion = strDatabasePath & "\green_price.b mp"
        Case Is <= 25
        fProdPriceCondi tion = strDatabasePath & "\yellow_price. bmp"
        Case Else
        fProdPriceCondi tion = strDatabasePath & "\tan_price.bmp "
        End Select

        End Function
        [/code]

        Simple enough so far - just a query to populate my subform and a function to show a simple condition.

        The subform has a image (rectangular bitmap) behind the Price column. The price column is set to transparent background.

        In Access2007 a new property for image controls is a Control Source (my control source is set to my function 'PriceCondition al' - see query).

        As you can see in my module I return the Control Source path to indicate which image to use behind each price.

        All images are linked and NOTembedded in the table thereby not increasing the size of the database.

        cheers,

        Originally posted by FishVal
        I don't have Access 2007, but still curious to know what method was applied to achieve the goal. Could you please describe the basics of your approach? Sure, not full how-to-do instructions - just few words about the main idea of the method.

        Regards,
        Fish.

        Comment

        • FishVal
          Recognized Expert Specialist
          • Jun 2007
          • 2656

          #5
          Nice solution. :)
          Thank you.

          Comment

          • mshmyob
            Recognized Expert Contributor
            • Jan 2008
            • 903

            #6
            Thank you.

            cheers,

            Originally posted by FishVal
            Nice solution. :)
            Thank you.

            Comment

            Working...