A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Setting Up & Running Reports
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Error Handling Problem



 
 
Thread Tools Display Modes
  #1  
Old August 15th, 2007, 11:58 AM posted to microsoft.public.access.reports
MarieM via AccessMonster.com
external usenet poster
 
Posts: 13
Default Error Handling Problem

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

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ports/200708/1

  #2  
Old August 15th, 2007, 01:58 PM posted to microsoft.public.access.reports
Ken Snell \(MVP\)
external usenet poster
 
Posts: 2,506
Default Error Handling Problem

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

--

Ken Snell
MS ACCESS MVP


"MarieM via AccessMonster.com" u30856@uwe wrote in message
news:76ba55d8515b1@uwe...
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

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ports/200708/1



  #3  
Old August 15th, 2007, 04:20 PM posted to microsoft.public.access.reports
Klatuu
external usenet poster
 
Posts: 7,074
Default Error Handling Problem

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

--
Dave Hargis, Microsoft Access MVP


"MarieM via AccessMonster.com" wrote:

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

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ports/200708/1


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:14 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.