Do you always avoid On Error Resume Next? (VB Only)
Updated by Brady Stroud [SSW] 1 year ago. See history
123
Never use On Error Resume Next in VB (and VB.NET) projects.
If an error occurred, On Error Resume Next will hide the error and things can go very haywire! In .NET, stop using the On Error syntax and use the try-catch exception syntax for better structural exception handling. In VB/VBA you should use On Error Resume Next with line of comment and after an offending line of code there should be statement On Error GoTo 0 to reset Errors collection.
Private Sub cmdSelect_Click()Dim varTemp As VariantOn Error Resume NextvarTemp = columnADOX.Properties("RelatedColumn").Value.....many lines of code....intRoutesPerDay = 2End Sub
❌ Figure: Bad Example – Bad code
Private Sub cmdSelect_Click()Dim varTemp As VariantOn Error Resume Next'Sometimes there is no related column valuevarTemp = columnADOX.Properties("RelatedColumn").ValueOn Error GoTo 0.....continuing code....End Sub
✅ Figure: Good Example – Good code