110 likes | 269 Views
Error Trapping Error Handling & other very practical uses for VBA in MS Access 2000 Part I. What is VBA. Visual Basic for Applications Work with complex logic (Case, Loops…) Allows use of constants and variables Perform Transaction Processing Create and work with DB objects in code
E N D
Error TrappingError Handling&other very practical uses for VBA in MS Access 2000Part I
What is VBA • Visual Basic for Applications • Work with complex logic (Case, Loops…) • Allows use of constants and variables • Perform Transaction Processing • Create and work with DB objects in code • Create libraries of user-defined functions • Call Windows API functions • Perform automation commands • Implement Error Handling and Error Trapping Error Handling - Part I
What is an Error • Every form & report contains an Error event • Form engine and report engine differ • Triggered by interface or by the engine • Error numbers range from 5 to 32,767 • Errors in VBA, Access, Jet, SQL, Windows • “Application-defined or object-defined error” • Some Jet errors use symbol | as placeholder Error Handling - Part I
Message displayed when Error Occurs Debug causes the VBE to appear Error Messaging Error Handling - Part I
Types of Errors • Synchronous Errors • Errors while code is running • Predictable • Most errors occur this way • Asynchronous Errors • Errors while code is NOT running • Unpredictable • i.e. Out of memory, network, bad data Error Handling - Part I
Error Commands • On Error • On Error Goto Error_Handler • On Error Resume Next • Exit • Exit Sub • Exit Function • Resume • Resume Next Error Handling - Part I
Error Flow Error Handling - Part I
Error Handling • Allow error to occur, then resume • Substitute error with code • Trap error and handle it • Bring up Message Box • Bring up Input Box • Bring up another form • Trap Error and Log to Errors Table Error Handling - Part I
Conclusion • Errors Happen ! • Can not trap errors with macros – use VBA • Errors in VBA, Access, Jet, SQL, Windows • Handle all predictable errors • Handle many unpredictable errors • Handle all errors “elegantly” • Explore Nesting Error Handlers • Explore User-Defined Errors Error Handling - Part I
Questions Error Handling - Part I