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
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...?
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.
Thanks for posting that. I haven't gone back and looked at conditional formatting for quite some time (don't often use it).
Jim.
DAveB_LDS
ASKER
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)
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.
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.
Alternatively, you could use the paint event to change the color.