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

Series of reports, one cancels, continue on with rest

Status
Not open for further replies.

bjzielinski

IS-IT--Management
Nov 8, 2001
93
US
I have a list of DoCmd.OpenReport statements connected to the click event of a button. Some of the reports could have no data, so it runs the NoData section of that report, which msgbox's "No Data" and cancel=true. I have an errortrap which handles the error, however, I do not know how to set it up so that it will continue processing the rest of the reports, those may have data. It just stops all together.

Private Sub cmdGo_Click()
On Error GoTo ErrorTrap
DoCmd.OpenReport "H Changes Fire"
DoCmd.OpenReport "H Changes Clerk"
DoCmd.OpenReport "H Changes Supervisor"
DoCmd.OpenReport "H Changes Postmaster"
DoCmd.Close acForm, "H DateRange"

ErrorTrap:
If Err.Number = 2501 Then
' Do nothing, keep going
Else
MsgBox Err.Number & vbCrLf & Err.Description
End If

End Sub

Perhaps I need a command in the 'Do Nothing section to return to the next line. I tried Return but that went in an endless loop. Bill Zielinski
bzielinski@co.midland.mi.us
County of Midland, Michigan
 
I can think of a couple things. I've seen the following several times:

On Error Goto 0

Then it will just keep going. 'On Error Resume Next' seems to do the same. Problem with that method is that you don't check the error before resuming.

If you want it to stop for any error beside 2501, the only way I can think of is to set up an error trap for each line. i.e.:

On Error GoTo ErrorTrap
DoCmd.OpenReport "H Changes Fire"
ErrorTrap:
...
On Error GoTo ErrorTrap2
DoCmd.OpenReport "H Changes Clerk"
ErrorTrap2:
...
On Error Goto Error Trap3
DoCmd.OpenReport "H Changes Supervisor"
...
 
This should work.

===========================================
Private Sub cmdGo_Click()
On Error GoTo ErrorTrap
DoCmd.OpenReport "H Changes Fire"
DoCmd.OpenReport "H Changes Clerk"
DoCmd.OpenReport "H Changes Supervisor"
DoCmd.OpenReport "H Changes Postmaster"
DoCmd.Close acForm, "H DateRange"

ErrorTrap:
If Err.Number = 2501 Then
Resume Next
ElseIf Err.Number = 0 Then
Exit Sub
Else
MsgBox Err.Number & vbCrLf & Err.Description
End If
End Sub

Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
 
Sorry about that, this is correct, I forgot the Exit

=============================================
Private Sub cmdGo_Click()
On Error GoTo ErrorTrap
DoCmd.OpenReport "H Changes Fire"
DoCmd.OpenReport "H Changes Clerk"
DoCmd.OpenReport "H Changes Supervisor"
DoCmd.OpenReport "H Changes Postmaster"
DoCmd.Close acForm, "H DateRange"

ErrorExit:
Exit Sub

ErrorTrap:
If Err.Number = 2501 Then
Resume Next
ElseIf Err.Number = 0 Then
Resume ErrorExit
Else
MsgBox Err.Number & vbCrLf & Err.Description
Resume ErrorExit
End If
End Sub Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
 
Try RESUME NEXT. Code will resume execution on the Next line following the error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top