Avatar of 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
Microsoft AccessVBA

Avatar of undefined
Last Comment

8/22/2022 - Mon
Jim Dettman (EE MVE)

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Anders Ebro (Microsoft MVP)

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 Coachman

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...?

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.
Your help has saved me hundreds of hours of internet surfing.
Jim Dettman (EE MVE)

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.

Jeffrey Coachman


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 Coachman

stopped trying after that, ...presumed limit was more than 21...
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jim Dettman (EE MVE)


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



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?

Jim Dettman (EE MVE)

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.

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Helen Feddema

See the Access Archon article I wrote on this topic:

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

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.