Feild Properties

A

AJOLSON

I have a report that I am trying to change the color of a query field
background if a condition is present.

In this case if the value of a field is > 2 I want the background to set to
vbRed

So I am trying to code this in “ Report loadâ€
I am typing this
Private Sub Report_Open(Cancel As Integer)
If October.Text > 2 Then
October.BackColor = vbRed
End If
End sub

I cant get this to work at all. First it tells me that the field has no
value, than when I get past that in does not execute the backcolor code.

Can anyone tell me how to get the background dof a field to change colors in
Reports?

Thank

Andy
 
J

John Spencer

First of all, you are doing this in the wrong place.

You need to use the format event of the section where the control October
exists. Also, use the Value property of the control. The Text property only
exists when a control has the focus (and I'm not it is even available in a
report). Finally, do you want to change from Red to White as you move from
record to record? Your code does not reset the value as it moves from record
to record.

I think you want something like the following.

If October.Value > 2 Then
October.BackColor = vbRed
Else
October.BackColor = vbWhite
End If

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
A

AJOLSON

John,

Thanks it is now somewhat working. At least now it goes into the if
Statement but does not execute the .BackColor command. It just goes in and
egnores that line.
 
J

John Spencer

Hmm.
Do you have a control named October?

Try
Me.October = vbRed
and then compile your code. Do you get an error when you compile?


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
A

AJOLSON

That got it done. The ultimate code that worked was this
If october.value > 2 then
Me.October.Backcolor = vbRed
else
Me.October.Backcolor = vbWhite
end if

Also changing the Back Style Properties of each field (in the form), to read
Normal ver. Transparent.

Works Like a charm now. Thanks for the help.
 

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