Posted By

RogerSpencelayh on 11/27/10


Tagged

error handler


Versions (?)

Tidy up and Error Handler


 / Published in: Visual Basic
 

  1. '-------------------------------------------------------------------------------
  2. ' Let the user know we're all done.
  3. '-------------------------------------------------------------------------------
  4.  
  5. MsgBox "Recruitment data import complete"
  6.  
  7. '===============================================================================
  8. ' Error Handling, object variable destruction and reset settings.
  9. '===============================================================================
  10.  
  11. TidyUp:
  12.  
  13. On Error Resume Next ' So we don't end up in an error loop
  14.  
  15. '-------------------------------------------------------------------------------
  16. ' Destroy any object variables.
  17. '-------------------------------------------------------------------------------
  18.  
  19. ' Set objSheet = Nothing
  20.  
  21. '-------------------------------------------------------------------------------
  22. ' Reset screen updating, alerts and the status bar.
  23. '-------------------------------------------------------------------------------
  24.  
  25. Application.ScreenUpdating = True
  26. Application.DisplayAlerts = True
  27. Application.StatusBar = False
  28. Application.Calculation = xlCalculationAutomatic
  29.  
  30. Exit Sub
  31.  
  32. ErrHandler:
  33.  
  34. Select Case Err.Number
  35. Case 1004
  36. If InStr(1, UCase(Err.Description), "SHOWALLDATA") Then
  37. Resume Next
  38. Else
  39. MsgBox "Error in Subroutine " & cStrSub & ", Module " & _
  40. cStrModule & "." & vbCrLf & "Error Number: " & _
  41. Err.Number & vbCrLf & "Description: " & Err.Description, _
  42. vbOKOnly + vbCritical, "Error Occurred"
  43. End If
  44. Case Else
  45. MsgBox "Error in Subroutine " & cStrSub & ", Module " & _
  46. cStrModule & "." & vbCrLf & "Error Number: " & _
  47. Err.Number & vbCrLf & "Description: " & Err.Description, _
  48. vbOKOnly + vbCritical, "Error Occurred"
  49. End Select
  50. Resume TidyUp
  51. Resume ' For use while debugging

Report this snippet  

You need to login to post a comment.