Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.

Slides:



Advertisements
Similar presentations
1 After completing this lesson, you will be able to: Create a database. Create a table using the Table Wizard. Create and modify a table in Design view.
Advertisements

MS Access 2003 Tutorial By: Juan GUANTENG!!! Y7. Step 1 Launch the Microsoft Access 2003 program. This can be done by clicking an icon on the desktop.
© Paradigm Publishing, Inc Excel 2013 Level 2 Unit 2Managing and Integrating Data and the Excel Environment Chapter 7Automating Repetitive Tasks.
1 Microsoft Access 2002 Tutorial 9 – Automating Tasks With Macros.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Excel Project 7 Using Macros and Visual Basic for Applications (VBA) with Excel.
Using Macros and Visual Basic for Applications (VBA) with Excel
XP New Perspectives on Microsoft Excel 2003, Second Edition- Tutorial 8 1 Microsoft Office Excel 2003 Tutorial 8 – Developing an Excel Application.
Microsoft Office 2010 Access Chapter 1 Creating and Using a Database.
Access Lesson 2 Creating a Database
Microsoft Office 2007 Access Chapter 2 Querying a Database.
Automating Tasks With Macros
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 2 1 Microsoft Office Access 2003 Tutorial 2 – Creating And Maintaining A.
Customizing Word Microsoft Office Word 2007 Illustrated Complete.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 1 1 Microsoft Access 2003 Tutorial 1 – Introduction To Microsoft Access 2003.
Microsoft Excel 2003 Illustrated Complete Excel and Advanced Worksheet Management Customizing.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
PYP002 Intro.to Computer Science Microsoft Word1 Lab 07 Creating Documents with Efficiency and Consistency.
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
Access Tutorial 10 Automating Tasks with Macros
Chapter 9 Macros, Navigation Forms, PivotTables, and PivotCharts
Chapter 2 Querying a Database
1 ADVANCED MICROSOFT WORD Lesson 15 – Creating Forms and Working with Web Documents Microsoft Office 2003: Advanced.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.
Microsoft Office 2007 Access 2007 Chapter 9 Administering a Database System.
Chapter 2 Querying a Database MICROSOFT ACCESS 2010.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 22 Macros.
1 CA201 Word Application Increasing Efficiency Week # 13 By Tariq Ibn Aziz Dammam Community college.
© Paradigm Publishing, Inc Access 2010 Level 2 Unit 2Advanced Reports, Access Tools, and Customizing Access Chapter 7Automating, Customizing, and.
Microsoft Expression Web-Illustrated Unit I: Working with Tables.
Chapter 6 Generating Form Letters, Mailing Labels, and a Directory
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
Office 2003 Advanced Concepts and Techniques M i c r o s o f t Access Project 6 Switchboards, PivotTables, and PivotCharts.
This tutorial teaches Microsoft Word basics. Although knowledge of how to navigate in a Windows environment is helpful, this tutorial was created for.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Microsoft Office 2007 Access Chapter 6 Using Macros, Switchboards, PivotTables, and PivotCharts.
Intro to Excel - Session 7.31 Tutorial 7 - Session 7.3 Developing an Excel Application.
XP 1 Microsoft Access 2003 Introduction To Microsoft Access 2003.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 2 1 Microsoft Office Access 2003 Tutorial 2 – Creating And Maintaining A.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Automating Database Processing
Key Applications Module Lesson 21 — Access Essentials
XP New Perspectives on Microsoft Access 2002 Tutorial 1 1 Microsoft Access 2002 Tutorial 1 – Introduction To Microsoft Access 2002.
Office Management Tools II Ms Saima Gul. Office Management Tools II Ms Saima Gul.
1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 8 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 8 Creating.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Access Project 7 Advanced Report and Form Techniques.
Microsoft Access 2010 Chapter 10 Administering a Database System.
Course ILT Forms and queries Unit objectives Create forms by using AutoForm and the Form Wizard, and add or modify form headers and footers Open and enter.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 7 – Creating and Using Templates in a Web.
Office 2003 Advanced Concepts and Techniques M i c r o s o f t Access Project 6 Creating an Application System Using Macros, Wizards, and the Switchboard.
® Microsoft Access 2010 Tutorial 10 Automating Tasks with Macros.
Access Lesson 11 Creating and Running Macros Microsoft Office 2010 Advanced Cable / Morrison 1.
Using Advanced Options Lesson 14 © 2014, John Wiley & Sons, Inc.Microsoft Official Academic Course, Microsoft Word Microsoft Word 2013.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 10 1 Microsoft Office Access 2003 Tutorial 10 – Automating Tasks With Macros.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
INTRODUCTION TO ACCESS. OBJECTIVES  Define the terms field, record, table, relational database, primary key, and foreign key  Create a blank database.
COMPREHENSIVE Access Tutorial 1 Creating a Database.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
Chapter 11 Enhancing an Online Form and Using Macros Microsoft Word 2013.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
Excel Tutorial 8 Developing an Excel Application
June 17, 2009 Office 2007 Tips & Tricks.
Using Macros, Switchboards, PivotTables, and PivotCharts
Access Chapter 2 Querying a Database.
Mail Merge And Macros in MS WORD
Administering a Database System
MODULE 7 Microsoft Access 2010
Microsoft Office Access 2003
Microsoft Office Excel 2003
Presentation transcript:

Macros Tutorial Week 20

Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with VBA Assign a macro to an application Switchboard at start up Add error messages through macros associated with events

What are macros? Macros are a means by which we can automate a process or group of processes. For example, in many Microsoft applications we can ‘record’ a macro to automate a task that the end user performs on a regular basis

Recording a macro A useful macro for a student to record would be to set up a Word document that can be used as a generic template for all the reports that need to be written for assignments Most academic reports require a contents list, page numbers, headings and a footer showing the authors name

Recording a macro To do this, create a new Word document Then select Tools, Macros, Record New Macro from the main menu

Recording a macro Give the macro a name You could assign the template to a keyboard shortcut, a toolbar or run it directly from the macro menu Click OK

Recording a macro Add the section headings and assign them to ‘Heading 1’ style Set each heading on a new page by pressing ctrl_Enter Add the footer with page numbers

Recording a macro Add appropriate table of contents from main menu Select ‘Table of Contents’ tab and click OK

Recording a macro Click ‘Stop Recording’ Close the document without saving The macro is now available to use

Playing a recorded macro Open a new document and select – Tools, Macro, Macros Find the recorded macro from the list and click ‘Run’ The document will open with your pre- formatted conditions

VBA – Visual Basic for Applications The actions performed whilst recording the macro have been converted into lines of Visual Basic code To view the code select Tools, Macro, Macros and then select the macro in the LH window and click ‘Step into’ – more on VBA later

VBA Code

Macros in MS Access To use macros in MS Access we have to use a different approach as we cannot ‘record’ the macro Before we create a macro we must consider what we want to automate As macros are based on VB code a macro can only respond to an ‘event’

Macros in MS Access There are many pre- written ‘actions’ that a macro can respond to To view these actions select the Macro option in the database design interface and click ‘New’

Macros in MS Access Click on the ‘Action’ dropdown list to view the actions

Macros in MS Access Now let us consider where we could use macros As computing students you will have to develop a software project, possibly using MS Access An Access project must have a menu structure to allow the end user to navigate though the system Access provides this functionality through a Switchboard

Switchboards An example of a switchboard is shown below

Switchboards When the user clicks on the database icon we would not normally expect them to have access to the development environment, only the menu (switchboard) To load the switchboard at the program start we can create a new macro named AutoExec

AutoExec Macro Assume that we have already created our Switchboard (a tutorial for creating switchboards is available) Click on ‘Macros’ in the development window and select ‘New’ Select ‘OpenForm’ from the action list and set the Form name to Switchboard – see next slide

AutoExec Macro Set the Data Mode to Edit Close and name the macro AutoExec There can only be one file of this name in any application

Setting Startup The next time you open the program it will look for the AutoExec macro and perform the actions assigned to it – in this case, open the Switchboard However, the end user still has access to the development environment To prevent this select Tools, Startup… from the main menu

Setting Startup Uncheck all the options in the dialog box to remove all development toolbars This is best performed after all development has been carried out However, after un-checking all the options you can access the development environment by pressing and holding the Shift key before clicking the icon to open the application

Multiple Actions It is possible to assign multiple actions to a macro, for example, if we wanted to open a ‘Clients’ table showing the records in descending order and set the window to maximised we would write the following macro

Multiple Actions The action ‘arguments’ are assigned in the bottom LH pane of the design window

Activating the macro To activate the macro we can either double click the macro name in the Macros window or assign it to an event If end-users only have access to the Switchboard then we will have to assign the macro to the click event of one of the switchboard menu buttons

Assigning a macro to an event Assuming that a Switchboard has been added to the application, click on Tools, Database Utilities, Switchboard manager – see below

Assigning a macro to an event If we have a menu structure similar to the one shown, click on Open Tables and select Edit Then click New – see next slide

Assigning a macro to an event Add a name in the Text textbox Select Run Macro from the Command list Select the OpenClientTable from the Macro List and click OK and close switchboard manager

Running the Switchboard Macro Open the Switchboard Click on Open Tables in the Main Switchboard Click on Open Client Table and the table will be displayed maximised and the data listed in descending order

Macro Conditions You may want to specify a condition i.e. do not display the table if there are no records to display To add conditions click on the ‘Conditions’ icon on the main menu bar and the conditions column is displayed

Building the Condition expression Right click on the row where you want to apply the condition and select ‘Build’ From the Built in Functions list select DCount Add the parameters to the Function

Building the Condition expression The DCount function will return the count of all the records in the Client table. The expression checks if count > 0 If the expression is true then all the actions displaying ellipses (… (denoting that the above condition also applies to these actions)) in the condition column are invoked – see next slide

Building the Condition expression If the condition is met then a message is displayed informing the user that the macro has been run

Adding Message Boxes If the expression returns false then all the actions with ellipses are ignored Below shows another condition which checks if there are no records – if true then display an appropriate message i.e. No Data to Display

Adding Macros to Property Events Another approach to assigning macros is to use the ‘Events’ of a control, form or report at design time For example, if we only want to display a report if there is data to display we could use the ‘On No Data’ event of the report

The following report asks the user to enter two date parameters and displays all orders between those dates Adding Macros to Property Events

The problem is that if there are no orders between those dates an empty report is displayed To remedy this we add the following macro to the On No Data event of the report If there is no data to display the message is displayed and the event is cancelled Adding Macros to Property Events

To access the On No Data event of the report, open the report in design view and click the Properties icon on the main menu Select the ‘Event’ tab and add the macro to the On No Data event The macro will only run if there is no data Adding Macros to Property Events

Summary In this tutorial we have looked at How to record a macro How to create an Access macro How to associate a macro with an event How to create an AutoExec macro How to associate the AutoExec macro with startup and the Switchboard How to add conditions to the macro How to create error/information messages in macros