Process order

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following code. I thought if I put Exit Sub after the error
message then the next line of code would not execute. For instance. If Dir
C:\My Documents\ does not exist then it will error. But when you click the
error message it shows the MsgBox "Exported to C:\My
Documents\BudgetExportCat.xls" which it should not show. How do I make it
bypass that message if there was an error.

Thanks,

Steven

Private Sub Command68_Click()
On Error GoTo Err_Command85_Click

Call ExportBudget
MsgBox "Exported to C:\My Documents\BExport.xls"

Exit_Command85_Click:
Exit Sub

Err_Command85_Click:
MsgBox Err.Description
Exit Sub


End Sub
 
Change the ExportBudget from Sub to function, and return a value if there was
error or not

Function ExportBudget()
On error Goto ExportBudget_Err
ExportBudget = True
' Your code
Exit function
ExportBudget_Err
ExportBudget = False
End Function
==============================
In the sub, change it to

Private Sub Command68_Click()
On Error GoTo Err_Command85_Click

If ExportBudget Then
MsgBox "Exported to C:\My Documents\BExport.xls"
End If
Exit_Command85_Click:
Exit Sub

Err_Command85_Click:
MsgBox Err.Description
Exit Sub


End Sub
 
Thank you for your help. Works great.

Ofer said:
Change the ExportBudget from Sub to function, and return a value if there was
error or not

Function ExportBudget()
On error Goto ExportBudget_Err
ExportBudget = True
' Your code
Exit function
ExportBudget_Err
ExportBudget = False
End Function
==============================
In the sub, change it to

Private Sub Command68_Click()
On Error GoTo Err_Command85_Click

If ExportBudget Then
MsgBox "Exported to C:\My Documents\BExport.xls"
End If
Exit_Command85_Click:
Exit Sub

Err_Command85_Click:
MsgBox Err.Description
Exit Sub


End Sub
 
Back
Top