Connecting Tech Pros Worldwide Help | Site Map

Demo of Conditional format in subform - Unlimited colours

mshmyob's Avatar
Expert
 
Join Date: Jan 2008
Location: witness protection
Posts: 614
#1   Apr 24 '09
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
File Type: zip conditionalsubform.zip (32.7 KB, 81 views)



NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,653
#2   Apr 24 '09

re: Demo of Conditional format in subform - Unlimited colours


I've moved this across to the Insights area (as well as noted so I can direct people here when required).
FishVal's Avatar
Expert
 
Join Date: Jun 2007
Location: Israel
Posts: 2,584
#3   Apr 25 '09

re: Demo of Conditional format in subform - Unlimited colours


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.
mshmyob's Avatar
Expert
 
Join Date: Jan 2008
Location: witness protection
Posts: 614
#4   Apr 25 '09

re: Demo of Conditional format in subform - Unlimited colours


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

Expand|Select|Wrap|Line Numbers
  1. SELECT tblVendor.VendorID, tblProduct.ProductID, tblProduct.ProductDesc, tblProduct.ProdPrice, fProdPriceCondition(ProdPrice) AS PriceConditional FROM tblVendor INNER JOIN tblProduct ON tblVendor.VendorID=tblProduct.VendorID WHERE tblProduct.VendorID=Forms![frmColumnConditional].txtVendorID; 
  2.  

Module Code

Expand|Select|Wrap|Line Numbers
  1. Public Function fProdPriceCondition(dblPrice As Double)
  2.  
  3. 'this function is used to determine the background colour for the product price
  4. ' this is an example of how to change the colour of a single control on each row of a subform
  5. ' 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
  6.  
  7. Dim strDatabasePath As String
  8.  
  9. ' get the path where the bitmaps are stored
  10. strDatabasePath = CurrentProject.Path
  11.  
  12. ' 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
  13. Select Case dblPrice
  14.     Case Is <= 10
  15.         fProdPriceCondition = strDatabasePath & "\red_price.bmp"
  16.     Case Is <= 15
  17.         fProdPriceCondition = strDatabasePath & "\pink_price.bmp"
  18.     Case Is <= 20
  19.         fProdPriceCondition = strDatabasePath & "\green_price.bmp"
  20.     Case Is <= 25
  21.         fProdPriceCondition = strDatabasePath & "\yellow_price.bmp"
  22.     Case Else
  23.         fProdPriceCondition = strDatabasePath & "\tan_price.bmp"
  24. End Select
  25.  
  26. End Function
  27.  
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 'PriceConditional' - 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,

Quote:

Originally Posted by FishVal View Post

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.

FishVal's Avatar
Expert
 
Join Date: Jun 2007
Location: Israel
Posts: 2,584
#5   Apr 25 '09

re: Demo of Conditional format in subform - Unlimited colours


Nice solution. :)
Thank you.
mshmyob's Avatar
Expert
 
Join Date: Jan 2008
Location: witness protection
Posts: 614
#6   Apr 25 '09

re: Demo of Conditional format in subform - Unlimited colours


Thank you.

cheers,

Quote:

Originally Posted by FishVal View Post

Nice solution. :)
Thank you.

Reply