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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing a report on NoData 1

Status
Not open for further replies.

TJones8

Technical User
Apr 16, 2002
77
GB
Hi all,
Is there any way to close a report when there is no data present??
I currently have a report with this code (and only this atm)

Code:
Private Sub Report_NoData(Cancel As Integer)
    MsgBox "No data was found, aborting...", vbCritical
    DoCmd.Close acReport, Me.Name, acSaveNo
End Sub

but this produces a run-time '2585:This action can't be carried out while processing a form or report event.'

I tried adding a 'DoEvents' before DoCmd.Close but that didn't work.

All i need is for the report to throw out an err msg and close itself, not throw out an error and open a blank report...

all help appriciated thx.


if at first you don't succeed, get a 10lb lump hammer
 
Code:
Private Sub Report_NoData(Cancel As Integer)
    MsgBox "No data was found, aborting...", vbCritical
    Cancel = True
End Sub[/code
 
argh!!
now i get a run-time '2501:The OpenReport action was canceled.'!!

but i've seen some other threads on the forum so i'll look at those to remove it...

if at first you don't succeed, get a 10lb lump hammer
 
You will need to add an error handler when you open the report. The simplest is to ignore any errors at all e.g.
Code:
On Error Resume Next
DoCmd.OpenReport "ReportName"
On Error Goto 0

The On Error Goto 0 line at the end resumes 'default' behaviour.
 
aye, that's pretty much what i did thx - my actual code is :-

Code:
On Error Resume Next
    DoCmd.OpenReport "ReportName"
    If Err.Number <> 0 Then If Err.Number <> 2501 Then MsgBox Err.Number & vbNewLine & Err.Description
    On Error GoTo 0
End Sub

thx alot peeps - problem solved :)

if at first you don't succeed, get a 10lb lump hammer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top