Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 460
  • Last Modified:

Setting text color on a subform

Hi,


i have a subform (with it's query) in datasheet mode. This subform displays some numeric and some non-numeric values. How can i set the text color of an entire row to i.e. red if a certain numeric field is negative? I tried with the Format function and with some VBA code (setting the ForeColor property) but with no results. Any suggestions ?
0
mario_34
Asked:
mario_34
1 Solution
 
VolibrawlCommented:
Sorry,  you CANNOT do what you have asked using a datasheet form.

Check this link for some discussion and solutions for continuous subforms (but not datasheet).

http://www.mvps.org/access/forms/frm0047.htm
0
 
VolibrawlCommented:
Sorry,  you CANNOT do what you have asked using a datasheet form.

Check this link for some discussion and solutions for continuous subforms (but not datasheet).

http://www.mvps.org/access/forms/frm0047.htm
0
 
nico5038Commented:
As stated above, marking a whole line can only be achieved in multiple form mode and not in datasheet mode...

If you have A2000 then you can use "Tools/Conditional formatting" on the field itself.
If you set the backgrounds of all other fields to Transparant, you can "expand" the "condition field" to be as wide as the whole line. (Using left/centre/right you can place the field content accordingly)
Now just place the field <0 condition to fill the background of your amount field...

For A97 stick to the above link.

Nic;o)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
I have a slightly different technique that works well.

First, you'll need a "color Table".  This is a table that contains one record per color that you want displayed.

tblColor
ColorID - PK autonumber
Description - Text
ColorBitMap - OLE

  The ColorBitMap field is filled by opening the table, and doing an insert of a MS Paint object.  In MS Paint, create a 16 x 16 pixel bitmap filled with the color you want.

Next you'll either need to add a "ColorID" field to your table or use a linking table (if multi-user, you will need to go the linking table route).

tblXXXXColorLink
ID - PK - PK from original table
ColorID - PK - ColorID to display.

Now in the query that the form is based on (or make one if you need to), join the original table, the linking table, and tblColor.

 In your form, set all existing controls background to transparent.  Now add a bound OLE control and size it to fit across whatever area you want highlited (it can be the whole record area).  Bind it to ColorBitMap, set it's size mode to Strech, and move it behind all other controls by using Format/Move to back.

That's it!  You can now control the color for each record based on colorID.  ColorID can be changed on the as needed based on any condition and you can use any number of colors that you want.

You can also use multiple colors for each row just by extending the linking table with more color fields.  Performance is suprisingly good. The only real drawback is populating the linking table.  There are different ways of handling that, but for anything under a 1,000 records or so I don't think you need to bother.

Let me know if you have any questions.
Jim.
0
 
mario_34Author Commented:
Hi Jim,

the technique you described works only on continuous forms or does it also work in datasheet view ?
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Just continuous forms.  Not much you can do with a datasheet.  Should have made that clearer.  

Sorry,
Jim.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now