How can I change controls on each row of a continuous form using VBA - Access 2013?

DAveB_LDS
DAveB_LDS used Ask the Experts™
on
I have a continuous form. Based on the value in each field I want to change the color of that cell. The color code is stored in another field of the record. I do not want to do this with conditional formatting
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012
Commented:
<<I do not want to do this with conditional formatting >>

 Reason?  There is the old school method of setting a controls background transparent, then placing a filled control behind it.

 In doing that, you can display a color, graphic, or whatever.   For colors, you can use a 1x1 bitmap stored in a "color table" and have it fill the control.  Quite fast that way and your not limited on the number of conditions.

 But it poses some problems as well.  Often you must then use a temp table for the form.

 Conditional formatting  is much easier.   i can walk you through the other however and have a sample database that I can attach that shows you how to do it.

Jim.
If you have a limited amount of colors, you could add a 1x1 bitmap to the "Shared Images", then give it a name matching the color, and bind an imagecontrol with Zoom to the field.

Alternatively, you could use the paint event to change the color.
Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
I am not aware of any disadvantages of using conditional formatting, ...so as Jim asked, ...can you tell us the reason why you are not considering this as an option...?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
There are 21 fields on each row of the continuous form. Each field could have 1 of 8 colors assigned to it. The corresponding color is kept in another 21 hidden fields of the form. Based on the value of the hidden field I want to change the color.
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
OK, your the first person in a long time that actually can't use conditional formatting<g>.

Attached is the sample DB that shows you how to do it.

With the technique I described, you can do any number of columns and conditions.

Jim.
ContinuousFormColors.MDB
Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
Jim,

I found no stated limits on the number of Rules in Access 2010-2013,.

I got up to 11 rules/11 fields with no problem...
Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
stopped trying after that, ...presumed limit was more than 21...
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
@Jeff,

 Thanks for posting that.   I haven't gone back and looked at conditional formatting for quite some time (don't often use it).

Jim.

Author

Commented:
Jim,

I'm running Access 2013 under Office 365, I can't open your sample database.

The basic question is really how can you get at controls in a continuous form after each row is rendered?

Dave
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
Sorry about that.  New one is attached.

<<The basic question is really how can you get at controls in a continuous form after each row is rendered?>>

  You don't, but the trick with continuous forms is that as long as you have bound controls, they are treated individually.

   That's why I mentioned temp tables.
 
   What you do is set all your current controls backgrounds to transparent.    Then place one (or more) image controls behind the normal controls (send to back) and set the mode to stretch.  These are bound to a bitmap field.

  I create a temp table with the PK from my main table along with the DisplayColorID field, then base the form on a query that joins the table I'm working to the temp table, and also my bitmap table  (I have seen where someone generated the bitmaps in memory, but I've never found the need to go that route - not sure I still have the example either).

  From that point on, it's automatic.   I change the color then by updating the DisplayColorID field in the temp table.

 Jim.
ContinuousFormColors_A2010.accdb
Top Expert 2009

Commented:
See the Access Archon article I wrote on this topic:
http://www.helenfeddema.com/Files/accarch173.zip

Here is a screen shot of the form:
Current row back color

Author

Commented:
Clever idea. However, I went with conditional formatting. Works well. The additional issue was I had to look at another field to determine the color. The data in the cell would not indicate the color.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial