Counter collapsing on no records

SueBK

Registered User.
Local time
Tomorrow, 04:16
Joined
Apr 2, 2009
Messages
197
I have a bunch of reports with the code below (highlighting every 2nd line). When there's no records to report, the code collapses ('cause you can't divide zero by 2). I've tried saying using 'recordset.recordcount <1 docmd.close" (or something like that), but it doesn't like the recordset deal for some reason. Says its not available in MDB, even though I've copied it from somewhere else where it does work.

Basically, what we want to happen:
- if there's no records, we want a message box on the preview command button that says "no records to view"
- if there are records we want to run the code below (which is on report open)

Code:
If Me.Counter / 2 <> Int(Me.Counter / 2) Then
    Me.Detail.BackColor = 14803425
Else
    Me.Detail.BackColor = 16777215
End If
 
Add this to the no data event

Cancel = True

which will also require you to trap for error 2501 in the code that calls the report. Either place is fine for adding your message box.
 
on error resume next
If Me.Counter / 2 <> Int(Me.Counter / 2) Then
Me.Detail.BackColor = 14803425
Else
Me.Detail.BackColor = 16777215
End If

alternatively add the above redline to intercept any error - however bear in mind that this will modify any existing error handler you are using
 

Users who are viewing this thread

Back
Top Bottom