Changing BackColor of fields conditionally

G

Guest

Hello

I have a continuous form with a textbox called txtGroupNum that holds a
value called GroupNum. In the underlying table, this is a req'd field
restricted to an integer from 1 to 9. When the form is first opened, this
field is null for each record.

I would like the backcolor to be red if the field is empty but white if it
has a value. I tried the following code, but it makes all of the fields
either red or all white. Any clues how I can 'red' only the null fields?

Sub txtGroupNum_AfterUpdate()
txtGroupNum = IIf(IsNull(GroupNum),255,16777215)
End Sub
 
F

fredg

Hello

I have a continuous form with a textbox called txtGroupNum that holds a
value called GroupNum. In the underlying table, this is a req'd field
restricted to an integer from 1 to 9. When the form is first opened, this
field is null for each record.

I would like the backcolor to be red if the field is empty but white if it
has a value. I tried the following code, but it makes all of the fields
either red or all white. Any clues how I can 'red' only the null fields?

Sub txtGroupNum_AfterUpdate()
txtGroupNum = IIf(IsNull(GroupNum),255,16777215)
End Sub

If your Access version is 2000 or newer, use conditional formatting.
Select the control you wish to format. Then click on Format +
Conditional Formatting.

Set the Condition1 to
Expression is.
Write:
IsNull([txtGroupNum])
in the next box.
Select the back color you wish.
Save the changes.
 
M

Marshall Barton

Sarah said:
Hello

I have a continuous form with a textbox called txtGroupNum that holds a
value called GroupNum. In the underlying table, this is a req'd field
restricted to an integer from 1 to 9. When the form is first opened, this
field is null for each record.

I would like the backcolor to be red if the field is empty but white if it
has a value. I tried the following code, but it makes all of the fields
either red or all white. Any clues how I can 'red' only the null fields?

Sub txtGroupNum_AfterUpdate()
txtGroupNum = IIf(IsNull(GroupNum),255,16777215)
End Sub


Use Confitional Formatting (Format menu) on the text box.
Set the Expression Is option to:
[txtGroupNum] Is Null
and choose red in the back color property.
 
G

Guest

Fine! Thanks to both fredg and Marshall

Marshall Barton said:
Sarah said:
Hello

I have a continuous form with a textbox called txtGroupNum that holds a
value called GroupNum. In the underlying table, this is a req'd field
restricted to an integer from 1 to 9. When the form is first opened, this
field is null for each record.

I would like the backcolor to be red if the field is empty but white if it
has a value. I tried the following code, but it makes all of the fields
either red or all white. Any clues how I can 'red' only the null fields?

Sub txtGroupNum_AfterUpdate()
txtGroupNum = IIf(IsNull(GroupNum),255,16777215)
End Sub


Use Confitional Formatting (Format menu) on the text box.
Set the Expression Is option to:
[txtGroupNum] Is Null
and choose red in the back color property.
 

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