Conditional formatting - what to do when no condition exists

RogerC

Well-known Member
Joined
Mar 25, 2002
Messages
536
I'm using the following code to change the color of a box in a report based on the results of a query. It works great as long as the query returns at least one record. However, sometimes the query will not return any records (and shouldn't). In this case, I need the formatting code to be ignored. Can anyone help me understand how to do this?

Private Sub Format_Box(Cancel As Integer, FormatCount As Integer)
If Event_Type = "CONFIRMED" Then
Box195.BackColor = 10787187
Else
Box195.BackColor = 11177338
End If

End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Re: Conditional formatting - what to do when no condition ex

dump the results of the query into a recordset variable then check it
if rs.recordcount <> 0 then
do the formatting code stuff here
endif
 
Upvote 0
Re: Conditional formatting - what to do when no condition ex

Thanks garyd1234. I'm just a beginner with Access and have never created a recordset variable. I can't find anything about it in Help. Can you give me an idea of how to do this?
 
Upvote 0

Forum statistics

Threads
1,221,811
Messages
6,162,109
Members
451,743
Latest member
matt3388

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top