Formatting

G

Guest

I posted this question in the general Access area earlier, but maybe I can
get a better answer in this forum.

I am trying to format the back color of a text box in a form, based on the
value in another text box. If this was Excel it would be easier to use
conditional formatting based onthe value of the second cell, but in A2000
there is no way that I am aware of, other than writing some code. So here is
what I have so far (that does not work):

Dim CAPR As String


CAPR = Text50.Text
If CAPR = "1" Then
txtSiteNum.BackColor = vbBlue
txtSiteNum.ForeColor = vbWhite
Else
txtSiteNum.BackColor = vbWhite
txtSiteNum.ForeColor = vbBlack
End If

I am not sure where there error lies or if this will even work. Any help
would be greatly appreciated.

Larry
 
R

Rick B

Please see your other post. Use conditional formatting. You can evaluate
any condition expression. Not just the current field.

Rick B
 
F

fredg

I posted this question in the general Access area earlier, but maybe I can
get a better answer in this forum.

I am trying to format the back color of a text box in a form, based on the
value in another text box. If this was Excel it would be easier to use
conditional formatting based onthe value of the second cell,
Regarding...
there is no way that I am aware of, other than writing some code.

Who says?
Click on the Control (in design View) and select
Format + Conditional Formatting. See below.
So here is
what I have so far (that does not work):

Dim CAPR As String

CAPR = Text50.Text
If CAPR = "1" Then
txtSiteNum.BackColor = vbBlue
txtSiteNum.ForeColor = vbWhite
Else
txtSiteNum.BackColor = vbWhite
txtSiteNum.ForeColor = vbBlack
End If
In Access, you would not reference a control's Text property, it would
be the control's Value property. Since the Value property is the
control's default property you do not need to explicitly state it.
You could re-write the above code like this:

Dim CAPR As String

CAPR = Text50
If CAPR = "1" Then
txtSiteNum.BackColor = vbBlue
txtSiteNum.ForeColor = vbWhite
Else
txtSiteNum.BackColor = vbWhite
txtSiteNum.ForeColor = vbBlack
End If

You can even shorten the above code:
No need to Dim CAPR as long as Text50 is a control on this form.

txtSiteNum.BackColor = Text50 = 1
txtSiteNum.ForeColor = Text50 = 1

You would place the above code in BOTH the Form's Current event as
well as the Text50 AfterUpdate event.

This will work in Single View Form View.
If you are using Continuous View Form, use Conditional Formatting.

In Design View, select [tstSiteNum].
Click Format + Conditional Formatting
Set the Condition1 to
Expression Is
In the next box write
[Text50] = 1
Set the Condition forecolor and backcolor as wanted.
 
R

Ron Kunce

Text50 appears to be a label type control, in which case you should be using
Text50.caption. There is no Text property for a label.
In fact, you could save a little memory by getting rid of the variable CAPR
and using a direct call

If Text50.caption = "1" then . . .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top