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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|