1 / 10

Error Handling & other very practical uses for VBA in MS Access 2000 Part II

Error Handling & other very practical uses for VBA in MS Access 2000 Part II. Error Categories. Syntax Errors Leaving a line of code Line of code changes color When VBA compiles code or module Runtime Errors (Synchronous & Asynchronous) Invoking an Error Handler Reacting to the Error

wes
Download Presentation

Error Handling & other very practical uses for VBA in MS Access 2000 Part II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Error Handling& other very practical uses for VBA in MS Access 2000Part II

  2. Error Categories • Syntax Errors • Leaving a line of code • Line of code changes color • When VBA compiles code or module • Runtime Errors(Synchronous & Asynchronous) • Invoking an Error Handler • Reacting to the Error • Exiting the Error Handler • Logic Errors • Improper logic • Code implications • Mistakes Error Handling & VBA - Part II

  3. Syntax Errors VBE | Tools | Options Immediately checks after line of code is entered Forces variable declaration with Option Explicit Info that completes code at insertion point Info about parameters allowed for functions Displays values over cursor only in break mode Error Handling & VBA - Part II

  4. Runtime Errors • On Error GoTo Error_Handler • Gives the most control for error handling • Causes VBA to jump to that location • On Error Resume Next • Allows for VBA to ignore error & continue • On Error GoTo 0 • Cancels the error handler • Resets the value of the Err Object Error Handling & VBA - Part II

  5. Logic Errors • Bugs! Me ? • Adhere to naming convention • Comment your code as much as possible • Require variable declaration • Fix logic errors as they appear • Use the tightest possible scope on variables • Avoid variant data type if possible • Organize, indent, group & label your code • Use sub-procedures and functions • Make one change at a time Error Handling & VBA - Part II

  6. Debugging Tools • Breakpoints and single step mode • Set locations where VBA temporarily halts • Single step one line at a time (F8) • Immediate window(CTRL G) • Investigate VBA effects directly • Always displays the last 200 lines of output • Data Tips work like Tool tips • Quick watches on variables(SHIFT F9) • MsgBox function Error Handling & VBA - Part II

  7. The Err Object Error Handling & VBA - Part II

  8. Error Handling Error Handling Flow Diagram Error Handling & VBA - Part II

  9. Conclusion • Errors Happen - Handle them “elegantly” • Error must be reproducible every time • Structure and comment your code • Use naming conventions • Organize, indent, group & label your code • Modularize your code • Use few or no global nor public variables • Make one change at a time and test Error Handling & VBA - Part II

  10. Questions Error Handling & VBA - Part II

More Related