Change color

I

Ivor Williams

I've a form on which there is a check box TaskComp and a text box TaskDate.
Using the following VBA code, when the check box is checked, the Date in the
text box is set to the current date. This works fine.


Private Sub TaskComp_AfterUpdate()

If TaskComp.Value = -1 Then TaskDate.Value = Date Else TaskDate.Value =
Null

End Sub


I want the background color of the text box to change from whit to red when
the check box is echecked, so I added to the code:

Private Sub TaskComp_AfterUpdate()

If TaskComp.Value = -1 Then TaskDate.Value = Date Else TaskDate.Value =
Null
If TaskComp.Value = -1 Then TaskDate.BackColor = 255 Else
TaskDate.BackColor = 16777215

End Sub

The date is updated as expected, but the text box background color is
changed in the text box for every record, not just the current one. Is there
a "work around" I can use to get what I'm after?

Ivor
 
A

Arvin Meyer [MVP]

If you are working in a continuous form or datasheet, the current record IS
the form. You can use an expression with conditional formatting to change a
record. In the form's design view, choose Format >>> Conditional Formatting,
and follow the wizard.
 
L

Linq Adams via AccessMonster.com

Your form is either in Continuous or Datasheet view, as evidenced by every
TaskDate box turning red. In these views you have to use Conditonal
Formatting to accomplish this. In Design View, select the TaskDate box, goto

Format - Condition Formatting

then Unde Condition1 select "Expression Is"

Type in [TaskComp] = -1

Now, using the background pallet, select your color for the background when
the checkbox is selected. When the condition isn't True the color will
revert to whatever the default is.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 

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