Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

AIA101.4.Automating Access


Published on

Last major module in AIA101 Accelerated Introduction to Access course. Illustrates advanced queries and macros.

Published in: Technology
  • Be the first to comment

AIA101.4.Automating Access

  1. 1. Module - Automating the Application - Advanced Queries, Macros, Control Wizards Microsoft Access P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 [email_address]
  2. 2. Module Outline <ul><li>Part 1: Advanced Queries </li></ul><ul><li>Part 2: Macros </li></ul><ul><li>Part 3: Control Wizards </li></ul>Three parts:
  3. 3. Module Hands On <ul><ul><li>Create action queries </li></ul></ul><ul><ul><ul><li>Maketable </li></ul></ul></ul><ul><ul><ul><li>Append </li></ul></ul></ul><ul><ul><ul><li>Delete </li></ul></ul></ul><ul><ul><li>Create macros </li></ul></ul><ul><ul><ul><li>Simple </li></ul></ul></ul><ul><ul><ul><li>Run from form </li></ul></ul></ul><ul><ul><ul><li>Add where criteria </li></ul></ul></ul><ul><ul><ul><li>Add a condition </li></ul></ul></ul><ul><ul><li>Use the control wizard to close a form </li></ul></ul><ul><li>Students “hands-on”: </li></ul>
  4. 4. MS Access Training Part 1 Advanced Queries
  5. 5. Advanced Queries <ul><li>Several types of special-use queries </li></ul><ul><ul><li>Action </li></ul></ul><ul><ul><ul><li>Make table* </li></ul></ul></ul><ul><ul><ul><li>Append* </li></ul></ul></ul><ul><ul><ul><li>Delete* </li></ul></ul></ul><ul><ul><ul><li>Update </li></ul></ul></ul><ul><ul><li>Other </li></ul></ul><ul><ul><ul><li>Pass-through, crosstab etc. </li></ul></ul></ul><ul><li>We will cover those with an *; others as time and interest permit </li></ul><ul><li>Reached through Query menu bar when query designer is open </li></ul>
  6. 7. MakeTable Query <ul><li>Allows you to create a new table based on a query </li></ul><ul><li>Can be output to current database or another one </li></ul><ul><li>Very simple </li></ul><ul><ul><li>Design your query as you normally would </li></ul></ul><ul><ul><li>Pull down the query menu and select make table. Assign the new table name </li></ul></ul>
  7. 8. MakeTable Query <ul><li>Create an extract of the Employees table </li></ul><ul><ul><li>Save table as Temp_Employees </li></ul></ul><ul><ul><li>Select MgrNo = 13 </li></ul></ul><ul><ul><li>Save your query as qryMake_Temp_Employees </li></ul></ul>
  8. 9. MakeTable Query Results
  9. 10. Append Query <ul><li>Appends records to an existing table </li></ul><ul><li>Design query then pull down query menu and select table to append to </li></ul><ul><li>Must indicate destination field for each source field in query. This is done in a new QBE grid row. </li></ul><ul><li>Can have additional “criteria” fields with no destination </li></ul>
  10. 12. Append Query <ul><li>Create and execute an append query </li></ul><ul><li>Select from Employees all records with MgrNo =12 </li></ul><ul><li>Append to table Temp_Employees </li></ul><ul><li>Save the query as qryAppend_Temp_Employees </li></ul>
  11. 13. Append Query Results
  12. 14. Delete Query <ul><li>Deletes records from an existing table </li></ul><ul><li>Go to query design window then pull down query menu and select table to delete from </li></ul><ul><li>Establish the criteria in the criteria row </li></ul>
  13. 15. Delete Query <ul><li>Delete from temp_employees </li></ul><ul><ul><li>All records with rate less than 20 </li></ul></ul>
  14. 16. Delete Query Results
  15. 17. Other Advanced Queries <ul><li>Union – “Adds” results of two queries into one result </li></ul><ul><li>Update – Update records in an existing table </li></ul><ul><li>SQL Pass-through – Send an SQL statement directly to “back-end” database (Oracle, DB2, etc.) </li></ul><ul><li>Crosstab – Creates a crosstab result (similar to a spreadsheet) </li></ul><ul><li>Etc. </li></ul>
  16. 18. Microsoft Access Part 2 Introduction to Macros
  17. 19. Introduction to Macros <ul><li>Two ways of “programming” a task in Access </li></ul><ul><ul><li>Macros </li></ul></ul><ul><ul><li>Visual Basic for Applications (VBA) </li></ul></ul><ul><li>We will cover Macros primarily </li></ul><ul><li>We will also take a look at control wizards which do use VBA </li></ul>
  18. 20. Introduction to Macros <ul><li>Elements of Macros </li></ul><ul><ul><li>Events – what “fires” the macro </li></ul></ul><ul><ul><li>Actions – what the macro does </li></ul></ul><ul><ul><li>Action arguments – control the specifics of the action </li></ul></ul><ul><ul><li>Conditions – circumstance under which the macro “fires” </li></ul></ul><ul><li>Macro design grid – how macro is defined </li></ul>
  19. 22. Introduction to Macros <ul><li>Create and run a simple macro, mcrFirst, to become familiar with the concepts </li></ul><ul><ul><li>Action = msgbox </li></ul></ul><ul><ul><li>Arguments: </li></ul></ul><ul><ul><ul><li>“ Hello, Macro” </li></ul></ul></ul><ul><ul><ul><li>information type </li></ul></ul></ul><ul><ul><ul><li>title = “My First Macro” </li></ul></ul></ul>
  20. 23. Designing the First Macro
  21. 24. My First Macro
  22. 25. Automating Import/Export with Macros <ul><li>Can string together several macros one after the other </li></ul><ul><li>Useful to do an import (or links, even) followed by data manipulation </li></ul><ul><li>As an example we will automate our prior three action queries </li></ul>
  23. 26. Import Macro <ul><li>Design a simple macro to import a table </li></ul><ul><li>Action is transfertext </li></ul><ul><li>Arguments are labor text file to be imported </li></ul><ul><li>Save as mcrImport </li></ul>
  24. 27. Designing Import Macro
  25. 28. Macro “Programs” <ul><li>Create a new macro to run the action queries created earlier </li></ul><ul><li>Use open query action </li></ul><ul><li>Use the action query name as the argument </li></ul><ul><li>Add a msgbox </li></ul><ul><li>Open the import table when done </li></ul><ul><li>Save as mcrActionQueries </li></ul>
  26. 29. More on Macros <ul><li>Macros can be invoked depending on “condition” </li></ul><ul><li>Uses a condition column </li></ul><ul><li>Macro will run iff condition is true </li></ul><ul><li>Macros can be run one after another like a “program”. Example: </li></ul><ul><ul><li>Do a maketable query , then an append query from a different file. I.E different downloads from an ERP system </li></ul></ul>
  27. 30. MS Access Training Part 3 Control Wizards
  28. 31. Control Wizards <ul><li>Will create program code for you to perform a task </li></ul><ul><li>Form operations </li></ul><ul><li>Report operations </li></ul><ul><li>Etc. </li></ul><ul><li>Invoked by making sure the wizard button is depressed when adding a control </li></ul>
  29. 32. Use Wizard Various Actions Using the Control Wizard
  30. 33. Form Events <ul><li>Forms and controls have “events” </li></ul><ul><li>These “fire” on certain actions. Examples: </li></ul><ul><ul><li>Click a button (onclick event) </li></ul></ul><ul><ul><li>Before table is updated (beforeupdate event) </li></ul></ul><ul><ul><li>After table is updated (afterupdate event) </li></ul></ul><ul><ul><li>Etc. </li></ul></ul>
  31. 34. Form Events (cont’d) <ul><li>When an event “fires” can execute: </li></ul><ul><ul><li>VBA Code </li></ul></ul><ul><ul><li>Macro </li></ul></ul><ul><li>This provides a method for “running” an application </li></ul>
  32. 35. Control wizards <ul><li>Create a criteria selection form </li></ul><ul><li>Add a button to run the action queries </li></ul><ul><li>Add a button to close the form </li></ul><ul><li>Run the form </li></ul><ul><li>That’s it! </li></ul>
  33. 36. Form with Button to Launch Macro
  34. 37. Microsoft Access End of Module P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472