Need help with conditional formatting

  • Thread starter Mister John Doe
  • Start date
M

Mister John Doe

I have a situation that has stymied me. Can anyone help?

I have a text box on a form. The text box name is Pages.

The Pages text box is being used to enter the number of pages that a
document has.

I have code checking for typical errors such as the following:
* non-numeric (such as XYZ or maybe the document title)
* NULL (nothing is entered at all)
* empty string (if the user enters something and then deletes it)
* Zero or less (a real document can't have zero pages or a negative
number)

So I display an error message to alert the user about any of these
conditions. So far all this works OK.

I have a lot of fields on the form, so I would like to set the
Conditional Formatting of each field to show when the field has one of
these error conditions.

I set the following Conditional Formatting for this Pages field:

Default formatting
For a required field the background color is a light blue. For a field
that is not required the background is white. In this case the Pages
field is required, so the default condition is set for having the
background color as light blue.

Condition 1
Field has focus: Set the background color to a light green.

Condition 2 (This is the one that doesn't work)
Here I want to have the Pages field display a background color of red
if the value entered into the field is zero or is a negative number. I
entered the following:
Field Value Is - Less Than Or Equal To - 0
And I set the background color to be red.

When I enter the value of zero the Pages field turns red (when I move
to another field). So this part shows that it works correctly for
entries of the number zero.

However, when I enter a negative number such as -3 or -9 and then I
move to another field, nothing happens here in the Pages field. That
is, the Pages field background color is light blue. It should be red
but it's not.

I looked into the Table of Contents for the HELP and I also searched
MSDN but it appears to me that I am doing things the way it's
described in those documents. Obviously I am not, so I don't know what
is wrong.

You won't believe how much time I have spent trying to figure out this
really small thing. How frustrating. So any advice is appreciated.
 
J

Jeff Boyce

Access treats the word "Pages" as a reserved word. First off, try a
different name for that textbox.

Take a look in HELP at the Format property -- I believe there's a way to
alter the color (?of the text) as part of the syntax of Format. Also,
depending on which version of Access you are using, check the Format |
Conditional Formatting feature.
 
M

Mister John Doe

Thanks for the suggestions. I renamed the field to NumPages.
Everything still behaves the same way.

I also had already gone through the MS HELP information both in Access
and on the MSDN site. I am using the version of Access that came with
Office 2003 so it has plenty of places to look for information.

It appears to me that I am doing everything the way the HELP says I
should. And, like I say, the one field works correctly when I enter a
number zero but doesn't work correctly when I enter a negative number.

Still stymied.
 
J

John Vinson

entered the following:
Field Value Is - Less Than Or Equal To - 0
And I set the background color to be red.

Try using an Expression rather than the Field Value; use an expression
such as

Val([textboxname]) <= 0

It appears that it may be treating the control as a Text string and
comparing the text string "-3" to the text string "0".

John W. Vinson[MVP]
 
M

Mister John Doe

I did what you suggested and it worked!!!

Thanks.

entered the following:
Field Value Is - Less Than Or Equal To - 0
And I set the background color to be red.

Try using an Expression rather than the Field Value; use an expression
such as

Val([textboxname]) <= 0

It appears that it may be treating the control as a Text string and
comparing the text string "-3" to the text string "0".

John W. Vinson[MVP]
 

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