Formatting

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I get a field on a report to print a black box if the field is null.

I tried using the conditional formatting function but it didn't give the
option to choose if the field was null.

I cannot change the data format because the data is from a linked table.
 
How about coding an OnFormat event for the field. Within that event, check
for null and alter the report field's properties based on whether the data
field is null or not.
 
In the section where the field is, open the "on print" properties of this
section, open the code and enter this code, changing to the name of your field

If IsNull(Me.FieldName) Then
Me.FieldName.BackColor = 4194368
Else
Me.FieldName.BackColor = 16777215
End If
 
There is another option given by Douglas J.Steele

From the Help file:

Custom number formats can have one to four sections with semicolons (;) as
the list separator. Each section contains the format specification for a
different type of number.

Section Description
First The format for positive numbers.
Second The format for negative numbers.
Third The format for zero values.
Fourth The format for Null values.

For example, you could use the following custom Currency format:

$#,##0.00[Green];($#,##0.00)[Red];"Zero";"Null"
 
Will this work if for several different fields? How would I seperate them in
the code window?

I have text fields numeric fields and date fields in this section. If any
of them are null I would like the same function.
 
Stefan,

Conditional Formatting would be the simplest approach. Select the
'Expression Is' option from the drop-down list of formatting types, and
then in the condition box, type the equivalent of...
[NameOfYourField] Is Null
 
You can use it for as many fields that you woud like, you just need to
seperate them if they are not depended on each other
If IsNull(Me.DateFieldName) Then
Me.DateFieldName.BackColor = 4194368
Else
Me.DateFieldName.BackColor = 16777215
End If
If IsNull(Me.TextFieldName) Then
Me.TextFieldName.BackColor = 4194368
Else
Me.TextFieldName.BackColor = 16777215
End If

If they are depended on each other, which mean it's enough that only one of
them will be null, to paint both of them in black then it will be
If IsNull(Me.TextFieldName) or IsNull(Me.DateFieldName) Then
Me.TextFieldName.BackColor = 4194368
Me.DateFieldName.BackColor = 4194368

Else
Me.TextFieldName.BackColor = 16777215
Me.DateFieldName.BackColor = 16777215

End If
 
Back
Top