Exploring Microsoft Office Access 2007

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Prentice Hall. All rights reserved Committed to Shaping the Next Generation of IT Experts. Exploring Microsoft Office Access.
Advertisements

Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational Databases.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
VBA Modules, Functions, Variables, and Constants
Automating Tasks With Macros
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
With Microsoft Access 2010© 2011 Pearson Education, Inc. Publishing as Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Access.
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.
By Mary Anne Poatsy, Keith Mulbery, Eric Cameron, Jason Davidson, Rebecca Lawson, Linda Lau, Jerri Williams Chapter 10 Using Macros and SQL in Access 1.
Adding Automated Functionality to Office Applications.
Access Tutorial 10 Automating Tasks with Macros
Chapter 9 Macros, Navigation Forms, PivotTables, and PivotCharts
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 4: Create, Edit, and Perform.
Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall1 Exploring Microsoft Office Access 2007 Committed to Shaping the Next Generation of.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Chapter 2 Querying a Database MICROSOFT ACCESS 2010.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Committed to Shaping the Next Generation of IT Experts. Chapter 1: Finding Your Way Through.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Committed to Shaping the Next Generation of IT Experts. Chapter 1: Finding Your Way Through.
Copyright © 2008 Pearson Prentice Hall. All rights reserved.1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational Databases.
Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational.
Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall1 Exploring Microsoft Office Access Committed to Shaping the Next Generation.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for 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.
Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 Committed to Shaping the Next Generation of IT Experts. Chapter 1: Finding Your.
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
11 Chapter 10 Customizing a Database with Macros and Visual Basic for Applications Exploring Microsoft Office Access 2007.
INSERT BOOK COVER 1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Excel 2010 by Robert Grauer, Keith.
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.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 11 Committed to Shaping the Next Generation of IT Experts. Chapter 10 Customizing a Database.
OCC Network Drives  H:\  P:\ 
Automating Database Processing
Copyright © 2008 Pearson Prentice Hall. All rights reserved Committed to Shaping the Next Generation of IT Experts. Chapter 7 Advanced Queries Robert.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 10 1 Microsoft Office Access 2003 Tutorial 10 – Automating Tasks With Macros.
Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 4: Create, Edit,
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
Chapter 11 Enhancing an Online Form and Using Macros Microsoft Word 2013.
A variable is a name for a value stored in memory.
Exploring Microsoft Office Access 2007
Exploring Microsoft Office Access 2007
Chapter 1: An Introduction to Visual Basic 2015
Access Project 8 Using Visual Basic for Applications (VBA) and Creating Multi-Page Forms.
Microsoft Access 2003 Illustrated Complete
Microsoft Access Illustrated
Using Procedures and Exception Handling
Microsoft Office Illustrated
Exploring Microsoft Office Access 2007
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
Tutorial 1 – Introduction To Microsoft Access 2003
Creating and Modifying Queries
CIS16 Application Programming with Visual Basic
Tutorial 1 – Introduction To Microsoft Access 2003
Exploring Microsoft® Access® 2016 Series Editor Mary Anne Poatsy
Tutorial 11 Using and Writing Visual Basic for Applications Code
Presentation transcript:

Exploring Microsoft Office Access 2007 Chapter 10 Customizing a Database with Macros and Visual Basic for Applications This chapters focus is on customizing a database. Robert Grauer, Keith Mulbery, Maurie Wigman Lockley Committed to Shaping the Next Generation of IT Experts. Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1

Copyright © 2008 Pearson Prentice Hall. All rights reserved. Objectives Understand the purpose of macros Create embedded macros using Wizards Create macros using the Macro Builder Assign macros to events Use SQL conditions to control macro actions The objectives for the chapter are: Understand the purpose of macros in Access databases; create embedded macros using Wizards; create macros using the Macro Builder; assign macros to events; and use SQL conditions to control macro actions. The objectives continue on the next slide. Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Copyright © 2008 Pearson Prentice Hall. All rights reserved. Objectives Understand Visual Basic for Applications (VBA) Use the Visual Basic Editor Create procedures Declare and use variables Manage data using SQL Additional Objectives for the chapter are: Understand Visual Basic for Applications (VBA); use the Visual Basic Editor; create procedures; declare and use variables; are manage data using SQL. Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Customization in Access Customization needed when additional functionality required Access provides two methods of Customization Visual Basic for Applications User creates code using VBA Macros Automates tasks Customization in Access is needed when additional functionality beyond the normal forms, reports, tables, and queries is required. This customization can only be gained through programming. Access provides two methods of customization. Visual Basic for Applications allows the user to create code for Access. Macros are an easier method than writing code and are good when you need to automate a task. Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Copyright © 2008 Pearson Prentice Hall. All rights reserved. Macros Two types of Macros in Access Embedded – belongs to a single object or control Standalone – used with more than one control Control – object in Access (textbox, list box) Macro Group Group of macros stored in a single macro object Macros add functionality to a database. They allow users to customize repetitive tasks and to group multiple tasks into one package. Macros can be thought of as a simplified programming language. They are recyclable – create once and run an infinite number of times. There are two types of Macros in Access. Embedded – belongs to a single object or control; and standalone – used with more than one control. Recall that a control is an object in Access such as a textbox or list box. You can also create macro groups, which is a group of macros stored in a single macro object. Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Creating an Embedded Macro Button Command Button Wizard To create an embedded macro, click the Design tab then click the button located on the Controls group, and the Command Button Wizard will begin. Click Design tab Click Button Controls Group Command Wizard begins Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Creating an Embedded Macro Choose a category Choose an action Choose object that the action will be performed upon Choose the appropriate category Choose action that you want to perform Click Next Select the object you wish to use Follow these steps to create an embedded macro: 1. Choose the appropriate category; 2. Choose the action that you want to perform; 3. Click Next; 4. Select the object you wish to use; 5. Click Next. Clicking Finish will result in no customization of the buttons (i.e., adding picture or title). Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Creating an Embedded Macro Specify how the button should work open an object Specify Text or graphic for the button Next, specify the action to take when the form is opened. Keep in mind, that many of the screens in this wizard will vary according to the object you are working with. Example purposes for which a form can been used are in the Wizard. Then, specify pictures or text for the button. Click Next. Specify action when form is opened Screen varies by object and action Specify text or graphic Click Next Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Creating an Embedded Macro Completed button In the last dialog box of the Wizard, you will provide a name for the button. You may then click Finish and test your button to see if it works appropriately. Finish Provide a name for the button Click Finish Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Creating Standalone Macros using the Macro Builder To create a macro using the Macro builder, click the Create tab and Macro in the Other group. The Macro builder will launch. Click the Create tab Click Macro Other group Macro Builder launches Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Creating Standalone Macros using the Macro builder 2. Argument appears here Select Action 1. Provide Argument Select the appropriate action, such as opening a form or query. Then provide the argument for the action. The argument for opening a form would be the form name. You can provide the argument in the lower section of the Macro builder. After providing the argument, it will appear in the top pane in the Arguments section next to its related action. Select Action Provide Arguments when necessary Value that provides information for action Run or Close and Save macro Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Copyright © 2008 Pearson Prentice Hall. All rights reserved. Assigning Events Property Sheet Events Choose object that the event is assigned to Event Action triggered by user or system Assign an Event Right-click, select properties Choose property-Event tab, Control list An event is an action that is triggered by the user or system. To assign an event to a standalone macro, right-click the macro and select properties from the short-cut menu. Choose property and the Property Sheet will open. Click the Event tab. Choose the event you want to use to trigger the macro. The macro you are assigning the event to should automatically appear in the section to the right of the chosen action. However, if it does not, you may click the for down arrow and choose the macro you desire from the drop-down list. Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Copyright © 2008 Pearson Prentice Hall. All rights reserved. Running a Macro Design view Click the Run button Form, Report or Table view Click button or perform assigned event Navigation Pane Double-click Macro Button in Form View There are several different ways to run macros. You may click the Run button in Design view or double-click the macro in the navigation pane. Of course you can also click or perform the assigned action in Form, Report or Table view to execute the macro. Navigation Pane Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Structured Query Language SQL statement SELECT fname FROM customer; Show (SELECT) me the records in the first name (fname) field that are in (FROM) the customer table SQL Defines and process database queries Industry standard query language Microsoft Access SQL Microsoft version of SQL Structured Query Language, or SQL defines and process database queries. SQL is the industry standard query language and Microsoft Access SQL is Microsoft's version of SQL. Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Database Analysis Tools SELECT fname FROM customer WHERE lname=“Smith” ORDER BY fname Returns records in the fname field only where the lname field is equal to Smith. Records are sorted in ascending order by first name Clauses Added to statements to restrict/specify records WHERE clause Specifies which records to return ORDER BY clause Specifies sort order Clauses can be added to select statement in order to restrict or further define query results. The WHERE clause specifies which records to return based on a condition – where this is equal to that or where this is true or that is false. The ORDER BY clause sorts records in either ascending or descending order and according to the field you specify. TO sort in descending order, add the keyword desc after the field name you are sorting by. Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Visual Basic for Applications Programming language Allows you to create/customize applications It is a host application Resides in Office application Visual Basic Editor Workspace for writing/editing VBA procedures Visual Basic for Applications is a programming language that allows you to create/customize applications. It is a host application in that it resides in the specific Office application you are working with. The Visual Basic Editor is a text editor that provides workspace for writing/editing VBA procedures. Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Launching the Visual Basic Editor VBA Editor There are three ways to launch the Visual Basic Editor: From the Macro group on the Database Tools tab; From the Event Property of an object/control; or By pressing Alt+F11 Three ways to launch editor Macro group, Database Tools tab Event Property of an object/control Press Alt+F11 Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Copyright © 2008 Pearson Prentice Hall. All rights reserved. VBA Terminology Comment – explains the code’s purpose Keyword – recognized as part of a language Syntax – rules for entering statements Standard Module – stores procedures used by events Class module – contains procedures for specific objects Option Explicit – helps eliminate common errors Let’s review some VBA terminology: A Comment explains the code’s purpose; A Keyword is recognized as part of a language; Syntax is rules for entering statements; A Standard Module stores procedures used by events; A Class module contains procedures for specific objects; and Option Explicit helps eliminate common errors. Terminology continues on the next slide. Copyright © 2008 Pearson Prentice Hall. All rights reserved.

VBA Terminology (cont.) Event – action that triggers program instructions Sub procedure – performs an action Property procedure – creates or manipulates custom properties Function procedure – performs action, returns value Public Procedure – available to all objects Private Procedure – available to a specific object Additional VBA terminology includes: An Event which is an action that triggers program instructions; A Sub procedure that performs an action; A Property procedure which creates or manipulates custom properties; A Function procedure which performs an action and then returns a value; A Public Procedure that is available to all objects; and A Private Procedure that is only available to a specific object. Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Copyright © 2008 Pearson Prentice Hall. All rights reserved. Creating Procedures Click Insert, Module To create a procedure in VBA, select Insert form on the menu bar and click Module. The new module appears and is ready for you to type in your code. New Module Select Insert on menu bar Select Module New module opens Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Creating Sub Procedures To create a Sub Procedure, you enter keyword Sub, enter the name of the procedure, enter a pair of parenthesis, and then enter End Sub. Enter keyword Sub Enter the name of the procedure Enter a pair of parenthesis Enter End Sub Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Copyright © 2008 Pearson Prentice Hall. All rights reserved. Decision Structures If Cost <=75 then purchase = 2 Performs logical test to compare statements Uses relations operators such as: = , < > equal to, not equal to <, > less than, greater than >= Greater than or equal to <= Less than or equal to Decision structures use relational operators to compare values in the programming statement and make a decision based on that comparison. Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Copyright © 2008 Pearson Prentice Hall. All rights reserved. Variables Named storage location in memory A variable’s scope limits accessibility Three different scopes Local – available to a specific procedure Global – available to any procedure Module-level – available to any procedure within module A variable is simply a named storage location in memory. All variable have scope – which limits accessibility to the variable. In VBA, you can use three different scopes: Local – available to a specific procedure; Global – available to any procedure; or Module-level – available to any procedure within a module. Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Naming and Dimensioning Variable name Data type Dim strName as string Dim intCost as int Dim (dimension) variables before using Use appropriate data type Name variables logically Use a meaningful name Variable12 not meaningful intQuantity meaningful Before using a variable, you must name and dimension the variable. Follow good practice when naming a variable and make sure the name reflect what the variable will be used for. Standard convention says to use an abbreviated form of the data type before the variable name. In other words a variable that will be an integer data type will have the letters int before the variable name. You use the Dim keyword to begin the dimension statement that allows you to specify both the name and the data type of the variable. Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Assign Values to Variables fname lname city John Doe Valdosta Memory Storage location named fname John = value Written fname = “John” Storage location named lname Doe = value Written lname= “Doe” In the example, the first storage location is named fname. A value has been assigned to that storage location. The value is John. In VBA we would assign the value to the variable in this manner: fname=“John”. Notice that character values go inside quotation marks. The second storage location is named lname. The value stored in that location is Doe. We would assign this value to the lname variable in this manner: lname = “Doe”. How would you write the assignment statement for the last variable? Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Copyright © 2008 Pearson Prentice Hall. All rights reserved. Call a Procedure Call to CloseForm Procedure Sometimes, you may want a procedure to become active while you are in another procedure. You can invoke, or call, a procedure by using the keyword Call and the procedure name, or by using only the procedure name. Call keyword or procedure name Can be used to activate another procedure Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Passing and “Catching” Arguments Argument passed to CloseForm procedure Passed to and “caught” here. Notice the variable names you are passing from and to do not have to match It may also be necessary to send the called procedure information (arguments). If this is so, the argument you want to send should be inserted into the parenthesis after the procedure name you are calling. The argument is then sent and “caught” inside the variable that is the argument for the procedure you are calling. Copyright © 2008 Pearson Prentice Hall. All rights reserved.

Copyright © 2008 Pearson Prentice Hall. All rights reserved. Be sure to read the material in the text carefully, complete the exercises as directed by your instructor, and ask questions as they arise. Copyright © 2008 Pearson Prentice Hall. All rights reserved. 28