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

Empty reports - how to avoid error

Status
Not open for further replies.

slames

Technical User
Nov 5, 2002
211
GB
Hi, I have some vba code which opens a series of reports as follows:

On Error GoTo Err_Command7_Click

Dim SinglesCatchup As Variant
Dim MultiplesCatchUp As Variant
Dim MagazineName As Variant
MagazineName = Me.Mag.Column(1)
MagazineName = MagazineName

SinglesCatchup = MagazineName & "_CATCHUPSINGLES"
MultiplesCatchUp = MagazineName & "_CATCHUPMULTIPLES"

DoCmd.OpenReport SinglesCatchup, acViewPreview
DoCmd.OpenReport MultiplesCatchUp, acViewPreview
DoCmd.OpenReport "CatchUpSummary", acViewPreview


Exit_Command7_Click:
Exit Sub

Err_Command7_Click:
MsgBox Err.Description
Resume Exit_Command7_Click


My problems is when the reports have no data they cause an error to occur which asks the user to end or debug and then presents the report in design view. I have some cod ein the on no data event but this is still happening and thus forcing itself out of the code and not continuing with the rest of it which is absolutely vital.

This is the code behind the report I am opening and is erroring on the first line of the first part:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)


If Me.Text149 = 2 Then
Me.Box54.Visible = True
Else
Me.Box54.Visible = False
End If
If Me.Text149 = 2 Then
Me.Image156.Visible = True
Me.Image157.Visible = False
Else
Me.Image156.Visible = False
Me.Image157.Visible = True
End If
End Sub

Private Sub Report_NoData(Cancel As Integer)
Dim emptyRecord As Variant

emptyRecord = MsgBox("No records for MET Multiple CatchUp", vbExclamation, "Warning: No Data")
Cancel = True
End Sub


How can I open all reports which have data and gracefully realise there is no data when this is true but still continue executing the subsequent code. I would be most greatful if anyone could help.

Thanks

Steph
 
I have sorted the closing report bit gracefully, but still can get the code to continue executing so I open the last report, do I need to write an error clause for each command I want to carry out?

Thanks
 
Have you tried inserting the following code in the On No Date event of your report? The report would close (without any popup messages) if there are no data and your VBA code will continue opening up your next report.

Code:
Private Sub Report_NoData(Cancel As Integer)
    Cancel = -1
End Sub

-Pete
 
Is this not the same as cancel = true as in my code above, or does equate to somehitng different?

My problem is the report doesn't open but the code still exits before it executes the next line as it has errored, even though it is catered for, in the report on no data event.

Do I need to write an error trap around each docmd.openreport statement?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top