• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 617
  • Last Modified:

Changing Font color in VB from one SubForm to the Main form in Access

I know the code for changing the font color in VB:

If [fieldvalue] < 0 then
[fieldvalue].forecolor = vbred
[fieldvalue].forecolor = (original color ) vb+color or rgb(87,171,83)
endif "green"

But can I change the font color from one subform to another?

Main form frmEditResources
Field I want to change to vbRed is First and last Name
SubForm: frmTotalAssigned_subform
Field is Balance (less than 0, name will change to Red.

Can this be done?
  • 2
1 Solution
Helen FeddemaCommented:
First, it's not the field that has color, but the control, so make sure you give your controls the appropriate prefixes (txt, cbo, etc.) to avoid confusion.  To reference a control on another subform of the same main form, use this syntax:

Parent![subCategories].Form![txtCategoryName].BackColor = vbRed

Open in new window

Helen FeddemaCommented:
In many cases, you can do color changes based on a field value using Conditional Formatting.  Here is an example:

Conditional Formatting expression
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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