Link to home
Start Free TrialLog in
Avatar of DAveB_LDS
DAveB_LDS

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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...?
Avatar of DAveB_LDS
DAveB_LDS

ASKER

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.
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
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...
stopped trying after that, ...presumed limit was more than 21...
@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.
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
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
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:
User generated image
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.