Microsoft Access Illustrated

Slides:



Advertisements
Similar presentations
Integrated Business Applications with Databases (D3) Jenny Pedler
Advertisements

Developing an Excel Application
Tutorial 8: Developing an Excel Application
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
With Microsoft Excel 2010 © 2011 Pearson Education, Inc. Publishing as Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Excel 2010.
VBA Modules, Functions, Variables, and Constants
Microsoft Excel 2003 Illustrated Complete with Excel Programming.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Using the Visual Basic Editor Visual Basic for Applications 1.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Adding Automated Functionality to Office Applications.
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
1 Chapter 9 Writing, Testing, and Debugging Access Applications.
XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter.
Automating Tasks with Visual Basic. Introduction  When can’t find a readymade macro action that does the job you want, you can use Visual Basic code.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Enhancing User Interaction Through Programming
INSERT BOOK COVER 1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Access 2010 by Robert Grauer, Keith.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
Chapter 11: Introduction to the Visual Basic Environment Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University.
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
Using Visual Basic for Applications (VBA) – Project 8.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 11 Committed to Shaping the Next Generation of IT Experts. Chapter 10 Customizing a Database.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
OCC Network Drives  H:\  P:\ 
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Introduction to Excel VBA UNC Charlotte CPE/PDH Series December 17, 2009.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Chapter 7 What’s Wrong with It? (Syntax and Logic Errors) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
Microsoft Visual Basic 2010 CHAPTER FOUR Variables and Arithmetic Operations.
Chapter 2: The Visual Studio .NET Development Environment
Using Macros, Switchboards, PivotTables, and PivotCharts
Chapter Topics 15.1 Graphical User Interfaces
Variables and Arithmetic Operations
1. Introduction to Visual Basic
Microsoft Access 2003 Illustrated Complete
Using Procedures and Exception Handling
Microsoft Office Illustrated
Microsoft Excel 2003 Illustrated Complete
PL/SQL Scripting in Oracle:
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
Chapter 7 Advanced Form Techniques
Variables and Arithmetic Operations
Exploring Microsoft Office Access 2007
Visual Basic..
Exploring Microsoft Excel
Exploring Microsoft® Access® 2016 Series Editor Mary Anne Poatsy
VB.NET PROGRAMMING FINAL EXAM TEST REVIEW.
Producing Triggers Schedule: Timing Topic 40 minutes Lecture
Chapter 15: GUI Applications & Event-Driven Programming
Tutorial 11 Using and Writing Visual Basic for Applications Code
Presentation transcript:

Microsoft Access 2013 - Illustrated Unit N: Creating Modules and VBA

Objectives Understand modules and VBA Compare macros and modules Create functions Use If statements Microsoft Office 2013 - Illustrated

Objectives (cont’d.) Document procedures Build class modules Modify sub procedures Troubleshoot modules Microsoft Office 2013 - Illustrated

Understand Modules and VBA Module: an Access object that stores Visual Basic for Applications (VBA) programming code Visual Basic Editor (VBE): program for writing VBA code Microsoft Office 2013 - Illustrated

Understand Modules and VBA (cont’d.) Two kinds of modules in an Access database Standard modules: contain global code executable from anywhere in the database Displayed as module objects in the Navigation Pane Class modules: code stored within the form or report object itself; can only be executed in that object Microsoft Office 2013 - Illustrated

Understand Modules and VBA (cont’d.) Module: contains VBA programming code organized in procedures Procedure: contains several lines of code; each line is a statement. Comments: text that helps explain and document the code Microsoft Office 2013 - Illustrated

Understand Modules and VBA (cont’d.) Procedure: a series of VBA statements Performs an operation or calculates an answer Two types of procedures: Functions Subs (sub procedure) Microsoft Office 2013 - Illustrated

Understand Modules and VBA (cont’d.) Function: a procedure that returns a value Sub: performs a series of VBA statements to manipulate controls and objects Arguments: constants, variables, or expressions Passed to a procedure; required in order for the procedure to execute Microsoft Office 2013 - Illustrated

Understand Modules and VBA (cont’d.) Object: any item that can be identified or manipulated Includes: traditional Access objects (table, query, form, etc.) as well as other items (e.g., controls, sections, and existing procedures) that have properties Method: an action that an object can perform Microsoft Office 2013 - Illustrated

Understand Modules and VBA (cont’d.) VBE window for a standard module Microsoft Office 2013 - Illustrated

Understand Modules and VBA (cont’d.) Components and text colors for the Visual Basic Editor window Microsoft Office 2013 - Illustrated

Understand Modules and VBA (cont’d.) Components and text colors for the Visual Basic Editor window (cont’d.) Microsoft Office 2013 - Illustrated

Compare Macros and Modules Macros: easy way to handle common, repetitive, and simple tasks Examples: open and close forms, show and hide toolbars, and print reports Macros: generally easier to create than modules Macro Design View is more structured than the VBE Microsoft Office 2013 - Illustrated

Compare Macros and Modules (cont’d.) Creating a module: requires VBA programming language knowledge Must apply correct syntax (rules) for each VBA statement Macros: simpler to create VBA: more powerful Macro: must be used to make global, shortcut key assignments Microsoft Office 2013 - Illustrated

Compare Macros and Modules (cont’d.) AutoExec: special macro name Automatically executes when the database first opens Use a module to: Create a unique function Detect Access error and display custom message Apply more powerful If-Then logic Microsoft Office 2013 - Illustrated

Compare Macros and Modules (cont’d.) Use a module to (cont’d.): Declare variables Work in conjunction with SQL (Structured Query Language) to select, update, append, and delete data Microsoft Office 2013 - Illustrated

Compare Macros and Modules (cont’d.) Visual Basic Editor window for a class module Microsoft Office 2013 - Illustrated

Common VBA keywords Microsoft Office 2013 - Illustrated

Common VBA keywords (cont’d.) Microsoft Office 2013 - Illustrated

Create Functions Access supplies hundreds of functions such as: Sum, Count, IIf, First, Last, Date, and Hour Create a custom function in a module Can be used in any query, form, or report throughout the database Microsoft Office 2013 - Illustrated

Create Functions (cont’d.) End Function statement Automatically added by VBA Required statement marking the end of a function Microsoft Office 2013 - Illustrated

Create Functions (cont’d.) Common VBA programming practice: apply three-character prefixes to name objects and controls Prefix bas: short for Basic; applies to global modules Microsoft Office 2013 - Illustrated

Create Functions (cont’d.) Microsoft Office 2013 - Illustrated

Three-Character Prefix Naming Conventions Microsoft Office 2013 - Illustrated

Use If Statements If...Then...Else logic: tests logical conditions and executes statements only if the conditions are true Microsoft Office 2013 - Illustrated

Document Procedures Comment lines: statements in the code that document the code; do not affect how the code runs Start with an apostrophe and are green in the VBE Microsoft Office 2013 - Illustrated

Document Procedures (cont’d.) Adding comments to a module Microsoft Office 2013 - Illustrated

Document Procedures (cont’d.) Standard toolbar buttons in the Visual Basic window Microsoft Office 2013 - Illustrated

Build Class Modules Class modules: contained and executed within specific forms and reports Most commonly run in response to an event (a specific action that occurs as the result of a user action) Microsoft Office 2013 - Illustrated

Build Class Modules (cont’d.) Creating an event handler procedure Microsoft Office 2013 - Illustrated

Build Class Modules (cont’d.) Copying the If structure to a new event-handler procedure Microsoft Office 2013 - Illustrated

Build Class Modules (cont’d.) Branch of Service combo box is visible when the Veteran check box is checked Microsoft Office 2013 - Illustrated

Modify Sub Procedures Sub procedures: can be triggered on any event identified in the Property Sheet Examples: On Got Focus (when control gets the focus), After Update (after a field is updated), or On Dbl Click (when control is double-clicked) Item’s set of event properties: depends on the type of item Microsoft Office 2013 - Illustrated

Modify Sub Procedures (cont’d.) IntelliSense technology prompts you as you write VBA statements Microsoft Office 2013 - Illustrated

Troubleshoot Modules Several techniques in Access for debugging different types of VBA errors Types of errors Syntax error: cannot be read by the Visual Basic Editor Occurs immediately as VBA statement is written Microsoft Office 2013 - Illustrated

Troubleshoot Modules (cont’d.) Types of errors (cont’d.) Compile-time errors: incorrectly constructed code Detected as soon as code is run or when Compile option selected on the Debug menu Run-time errors: incorrectly constructed code; stops code execution Examples: attempting an illegal operation e.g., dividing by zero Microsoft Office 2013 - Illustrated

Troubleshoot Modules (cont’d.) Types of errors (cont’d.) Logic errors: code runs without obvious problems; procedure does not produce the desired result Most difficult errors to troubleshoot Microsoft Office 2013 - Illustrated

Troubleshoot Modules (cont’d.) Setting a breakpoint Microsoft Office 2013 - Illustrated

Troubleshoot Modules (cont’d.) Stopping execution at a breakpoint Microsoft Office 2013 - Illustrated