Error Handling Problem

  • Thread starter MarieM via AccessMonster.com
  • Start date
M

MarieM via AccessMonster.com

I have a Purchase Order database which includes the Purchase Order form with
a subform which contains the PO details.
The form includes a button which when the user clicks the PO displays in
Print Preview mode.
Attached to the report's On Open property I have the following code which
checks to determine if the total of the PO is over $5000. If so, a message
displays alerting the user and the report is canceled.
This is working great, however, it also displays the the "Open Report
canceled action" message which I would like to hide from the user.
I tried adding the following error handling code without any luck. The
message still displays.
Is this the appropriate place to put the code and if so, could someone please
give me a hand with the code.

Thanks in advance for your help!
Marie

Private Sub Report_Open(Cancel As Integer)
On Error GoTo OpenReport_Err

If DSum("[ExtendedPrice]", "qryPODetailssubrpt", "PONumber = PONumber") >
5000 Then
MsgBox "The PO Total must not exceed $5000."
Cancel = True
'On Error Resume Next
Exit Sub
Else
DoCmd.OpenReport "rptPurchaseOrder", acViewPreview
DoCmd.Maximize
End If

OpenReport_End:
Exit Sub

OpenReport_Err:
If Err.Number = 2501 Then
Resume OpenReport_End
Else
MsgBox Err.Number & " " & Err.Description
Resume OpenReport_End
End If

End Sub
 
K

Ken Snell \(MVP\)

The capture of the error number 2501 (from cancelling the report's open
event) must be done in the form that opens the report.
 
G

Guest

You have more code than necessary in the report's open event. To stop the
message, you trap for for the 2501 error in the procedure in the form module
that has the Open Report method:

Private Sub Report_Open(Cancel As Integer)

On Error GoTo Report_Open_Err

If DSum("[ExtendedPrice]", "qryPODetailssubrpt", "PONumber = PONumber") >
5000 Then
MsgBox "The PO Total must not exceed $5000."
Cancel = True
End If

Report_Open_Exit:
Exit Sub

Report_Open_Err:
MsgBox Err.Number & " " & Err.Description
GoTo Report_Open_Exit
End If

End Sub

*********************
In the form

Private Sub cmdReport_Click()

On Error GoTo cmdReport_Click_Err

DoCmd.OpenReport "rptPurchaseOrder", acViewPreview

cmdReport_Click_Exit:
Exit Sub

cmdReport_Click_Err:
If Err.Number <> 2501 Then
MsgBox Err.Number & " " & Err.Description
End If
GoTo cmdReport_Click_Exit

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top