Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional formatting for Null Value

Status
Not open for further replies.

nunan

Technical User
Feb 11, 2004
41
GB
Hi all

I know what I am trying to do is simple but I just can't get the expression correct!

All I want to do is have a fields background colour red if there is no data in it and change to white when data is entered.

The field is called Phone and is text format.

Thanks for any help
 
Is this a single form or a continuous form? Please post the code you have tried.
 
Hi

It is a single form. I tried this from MShelp but no joy!

=IIf(IsNull([Phone]) and then set the back colour to red
 
You need code in an event. First, try the After Update event of the Phone textbox. When you get that working, add the same code to the Current event of the form. Paste this snippet into the After Update event and see how you get on:

Code:
If Trim(Me.Phone & " ")<>""
'Not empty
    Me.Phone.Backcolor=vbWhite
Else
'Empty
    Me.Phone.Backcolor=vbRed
End If

 
Hi

Your code returns and error on:

If Trim(Me.Phone & " ")<>""

I am sure this can be done with conditional formatting if the expression is correct!

Thanks for your help.
 
I always forget 'Then'.

If Trim(Me.Phone & " ")<>"" Then
 
I assume you were trying to place your code in the Conditional Format section from the menu. This is very limiting, and Remou's method much more flexible.

BTW, the IIF function is not the same as using the If...Then construct. It's a kind of shortcut for that, but rquires a couple of arguements to work right.

OrderSize = IIf([OrderAmount] > 1000, "Large", "Small")

will result in

OrderSize = "Large" if OrderAmount is greater than 1000

or

OrderSize = "Small" if OrderAmount is 1000 or less

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
What about replacing this:
=IIf(IsNull([Phone]))
with this ?
=IsNull([Phone])

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks Remou

It now works perfectly, I have placed it on both OnCurrent for the form and AfterUpdate for each control I wanted it to work on.

Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top