Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
AMP110 Microsoft Access Macros
1. Orange Coast Database Associates Course (800)355-9855 or http://ocdatabases.itgo.com
AMP110 Microsoft Access Macros
Orange Coast
Database Associates
Specializing in Microsoft Office,
Access, SQL, and related technologies
Classes custom designed for Working Professionals
http://www.dhdursoassociates.com
San Juan Capistrano, CA
(800)355-9855
Accelerated Computer Training for Working Professionals Factory 2010 Case
2. AMP110 - Introduction to Access
Macros
Quick introduction to Access
Macros for experienced Windows
users
P.O. Box 6142
Laguna Niguel, CA 92607
949-489-1472
http://www.d2associates.com
1 Factory AMP110
MS Access Introductory (100 Level)
Curriculum
AIN100
AIN100T A, B
AIA101
AIN104
AIN102 AMP110
Reports
Queries Macros
& Forms
2 AMP110 Factory
3. AMP110 - Introduction to Access
Macros
Introduction (s)
Facilities
Course Packet (May vary by course and class)
– Student Questionnaire
– Collaterals (Catalogs, etc.)
– PowerPoint handouts for all sessions
– Evaluation form in back
– Training certificate
3 AMP110 Factory
AMP110 – Introduction to Access
Macros
Quick pace for experienced windows users
Assumes prior knowledge of Access equivalent
to AIA101/AIN100
End-user, not programmer, oriented
Somewhat structured towards personal use for
analysis and reporting
4 AMP110 Factory
4. AMP110 - Introduction to Access
Macros
Course Topics:
Macros (90% of class)
Hot Keys, etc.
Switchboards (2007) or
Navigation Forms(2010)
5 AMP110 Factory
Introduction to Access Macros
Industry Standard Approach:
Access has many ways to accomplish tasks. As an accelerated
course we will cover only the most common.
Tables Table Designer
Queries Query designer
Reports Wizard then modify
Forms Wizard then modify
Macros Macro Designer
6 AMP110 Factory
5. AMP110 - Introduction to Access
Macros
Course Format:
2 Sessions
Lecture
Demo
Student “hands-on” - by the end of the
class the student will have added macros to
a small sample application
Exercises are cumulative – later examples
build on objects created earlier
7 AMP110 Factory
AMP110 - Introduction to Access
Macros
Course Schedule (3 hour sessions):
Session 1
– Macro Concepts
Session 2
– Using Macros
– Switchboards (2007) or
– Navigation Forms (2010)
8 AMP110 Factory
6. Microsoft Access
Module – Macro Concepts
P.O. Box 6142
Laguna Niguel, CA 92607
949-489-1472
http://www.d2associates.com
1 Factory Access Macros
Module Outline
Two parts:
Part 1: Basic Macro concepts
Part 2: Form concepts
Part 3: Building a macro “group:
Part 4: Introduction & Keyboard
shortcuts
2 Access Macros Factory
7. Module Hands On
Students “hands-on”:
– Create macros
Simple
Run from form
Add where criteria
Add a condition
Add another command
Custom keys
3 Access Macros Factory
Sample Application – Factory2000
Simple cost accounting
application
Employees work on work
orders
Clock labor hours for each
work order
4 Access Macros Factory
9. Microsoft Access
Part 1
Introduction to
Macro concepts
7 Factory Access Macros
Introduction to Macro
Programming
Two ways of “programming” a task
in Access
– Macros
– Visual Basic for Applications (VBA)
We will cover Macros primarily
We will also take a look at control
wizards which do use VBA
We do have two Access VBA courses you
can take
8 Access Macros Factory
10. Types of Macros
Standalone
Data
Embedded
9 Access Macros Factory
Introduction to Macro
Programming
Macros are not coded – they are
designed using a Macro Designer
They run in response to an “event”
– like when a form launches or the
user clicks on a button
10 Access Macros Factory
11. Some Common Events
Common button event
– “On Click”
Common form events
– On Load
– On Activate
– On Current (record)
– On insert/update/delete (records)
– On Close
11 Access Macros Factory
Introduction to Macros
Elements of Macros
– Actions – what the macro does
– Action arguments – control the specifics of the
action
– Name – Allows you to store multiple macros within
a single macro “object”
– Conditions – circumstance under which the macro
“fires”
12 Access Macros Factory
12. Typical Actions
Apply Filter
Cancel event
Go to control/record
Minimize/Maximize
Open form/report/query
Set value
Select object
Transfer spreadsheet
Transfer text
13 Access Macros Factory
Macro Design Grid
14 Access Macros Factory
13. Introduction to Macros – Actions &
Arguments
Create and run a simple macro, mcrFirst,
to become familiar with the concepts
– Action = msgbox
– Arguments:
“Hello, Macro”
information type
title = “My First Macro”
15 Access Macros Factory
Designing the First Macro
16 Access Macros Factory
14. Designing the First Macro
17 Access Macros Factory
My First Macro
18 Access Macros Factory
15. Design | Macro Tools
19 Access Macros Factory
Comments
Use the
comment action
to comment your
macros
Always a good
idea
20 Access Macros Factory
16. Submacros
Same idea as a programming subroutine
Used to store common actions that are used
repeatedly
Submacros are NOT run unless you call them
by name
You call them with programming “dot
notation”…
Macroname.submacroname
21 Access Macros Factory
Submacros
22 Access Macros Factory
17. Groups
Another way to create subroutines or blocks of
macros (submacros)
Hold over from 2007 which we won’t use in the
course
23 Access Macros Factory
Conditional Macros (If)
Use if to create
a macro that
runs only when
certain
conditions are
met
24 Access Macros Factory
18. Microsoft Access
Part 2
Form concepts
25 Factory Access Macros
Form Events
Forms and controls have “events”
These “fire” on certain actions. Examples:
– Click a button (onclick event)
– Before table is updated (beforeupdate event)
– After table is updated (afterupdate event)
– Etc.
26 Access Macros Factory
19. Form Events (cont’d)
When an event “fires” can execute:
– VBA Code
– Macro
This provides a method for “running” an
application
Macros will appear in the event drop down list
27 Access Macros Factory
Event List with Macros
28 Access Macros Factory
20. Microsoft Access
Part 3
Building a macro
Group
29 Factory Access Macros
Building a Macro Group
We will build a series of submacros in a macro.
– Open report
– Open report with filter
– Open report with filter conditionally
These will be run from a form with a button
using the OnClick event of the button.
30 Access Macros Factory
21. Open Report Macro
Design a simple macro to open
(run) a report for the displayed
form record
Use rptWork_OrdersFull
Give this macro the name
work_Orders Report
Save the “group” as mcrReports
Note: it won’t run right just yet – still has
all records
31 Access Macros Factory
Designing The Open Report Macro
32 Access Macros Factory
22. Invoking the macro
Add a command button to the form
Bring up properties sheet, events tab
Click the drop down for the On Click Event
Select your macro
That’s it!
33 Access Macros Factory
Use Onclick Event to “Fire” the Macro
34 Access Macros Factory
23. Select Macro
35 Access Macros Factory
Invoking the macro
Open the frmWork_OrdersFinal form
in design mode
– Add a command button to the form with
control wizard off
– Bring up properties sheet, events tab
– Click the drop down for the On Click Event
– Select your macro
– That’s it!
Save as frmWork_OrdersMacro
(instructor may use AMP110 or other suffix for this class)
36 Access Macros Factory
24. Adding Where Conditions to a
Macro
Use action argument where
Create a filter like the where clause of
an SQL statement
37 Access Macros Factory
Using the Expression Builder for the Where Condition
38 Access Macros Factory
25. Where Condition (in Zoom Window)
39 Access Macros Factory
Macros - Adding a where clause
Open mcrOpenReport in design mode
Add a where criteria to preview only the work
order on the screen. Put this in a new submacro.
Click to right of where in macro property sheet
Use the builder to get name of form text control,
etc. Your expression will look like this:
– [wono]=[Forms]![frmWork_OrdersMacro]!
[Wono]
Save the macro under the same name (instructor
may use a slightly different name)
40 Access Macros Factory
26. Invoke the macro
Open the frmWork_OrderMacro
in design mode
Update the preview button to use
the new submacro
Observe that the form only prints
detail for the work order selected
in the form!
41 Access Macros Factory
Macro Group w/ where Macro
added
42 Access Macros Factory
27. More on Macros
Macros can be invoked depending on
“condition”
– Uses an if macro
– Macro will run if and only if condition is true
Macros can be run one after another like a
“program”. Example:
– Do a maketable query , then an append query from
a different file. I.E different downloads from an ERP
system
43 Access Macros Factory
Conditional Macros
Modify your mcrOpenReport to check for a
missing work order number before doing a
report
Add a new action like the mcrFirst to print
“Please select a work order number”
Add a condition to each to check to see if wono
is null
Use the builder if desired
Name submacro OpenReport_Condition
Save macro group with same name
44 Access Macros Factory
28. Using the Builder to Create a Macro Condition
45 Access Macros Factory
Invoking the Conditional Macro
Modify the form
frmWorkOrders_Macro to
run the new macro
Save as
frmWorkOrders_MacroFinal
Test your new form and
macro
46 Access Macros Factory
29. Macro Group with new conditional
macro
47 Access Macros Factory
Adding Commands to a Macro
Move focus on form back to wono
when an error occurs
Add a go to control action
Save your macro as
mcrOpen_Report_Final
48 Access Macros Factory
30. Final Submacro in Design Mode
49 Access Macros Factory
Macro Messages
Often want to suppress messages when
running a macro
– Set warnings off
– Echo off
50 Access Macros Factory
31. Microsoft Access
Part 4
Custom key
Assignments
51 Factory Access Macros
Custom Key Assignments
Can customize keyboard shortcuts in two
ways:
– Access keys
– Key Assignment macros
52 Access Macros Factory
32. Access Keys (Hot Keys)
53 Access Macros Factory
Custom Key Assignments
Access has many built-in keyboard shortcuts:
CTRL-G to open Debug Window, F11 to
display Database Window, etc. See Help.
Can also create your own using macros – we
will cover this in module 2
54 Access Macros Factory
33. Microsoft Access
End of Module
P.O. Box 6142
Laguna Niguel, CA 92607
949-489-1472
http://www.d2associates.com
55 Factory Access Macros
34. Microsoft Access
Module – Using Macros to Automate
Your Application
P.O. Box 6142
Laguna Niguel, CA 92607
949-489-1472
http://www.d2associates.com
1 Factory Access - Using Macros
Module Hands On
Students “hands-on”:
– Create macros
Imports
Exports
Startup (AutoExec)
AutoKeys
Set Values on a form
Data Macros
Macros to code
– Use the control wizard to close a
form
2 Access - Using Macros Factory
35. Introduction to Macros
Two ways of “programming” a task
in Access
– Macros
– Visual Basic for Applications (VBA)
We will cover Macros primarily
We will also take a look at control
wizards which do use VBA
3 Access - Using Macros Factory
Introduction to Macros
Elements of Macros
– Events – what “fires” the macro
– Actions – what the macro does
– Action arguments – control the specifics of the action
– Conditions – circumstance under which the macro “fires”
Macro design grid – how macro is defined
4 Access - Using Macros Factory
36. Macro Designer
5 Access - Using Macros Factory
Some Available Actions
Apply Filter
Find
Go
Max/minimize
Open
Run
Set
Transfer
6 Access - Using Macros Factory
37. Form Events
Forms and controls have “events”
These “fire” on certain actions. Examples:
– Click a button (onclick event)
– Before table is updated (beforeupdate event)
– Before a record is deleted
– After table is updated (afterupdate event)
– After the user leaves a control
– Etc.
7 Access - Using Macros Factory
Form Events (cont’d)
When an event “fires” can execute:
– VBA Code
– Macro
This provides a method for “running” an
application
8 Access - Using Macros Factory
38. Import/Export Form
Create a simple, unbound form named frmData
We will use it to drive a series of very useful
import and export macros
9 Access - Using Macros Factory
Import/Export Form
10 Access - Using Macros Factory
39. Export Macro
Design a simple macro to
export our three main tables
to text files – use transfer text
Export order is not critical
Let’s put them into a data
macro group
Group name mcrData
Macro name export_all
11 Access - Using Macros Factory
Designing The Export Macro
Note: can use saved spec
12 Access - Using Macros Factory
40. Invoking the macro
Open the frmData form in design mode
– Add a command button to the form with wizard
enabled
– Select run macro
– Select your macro
– That’s it!
Save with same name (instructor will use a
different name for this working form)
13 Access - Using Macros Factory
Use Control Wizard to “Fire” the Macro
14 Access - Using Macros Factory
41. Select Your Macro
15 Access - Using Macros Factory
New Data Form with Macro Button
16 Access - Using Macros Factory
42. Export Your Data
Run the export macro – check for files
17 Access - Using Macros Factory
Macros - Adding the Imports
Open mcrOpenData in design mode
Add the imports
Call the macro import_all
Link the two parent text files to
work_orders_linked and employees
_linked
Import the labor_export text file to
labor_import
18 Access - Using Macros Factory
43. Creating the Import Macro
19 Access - Using Macros Factory
Invoke the macro
Open the frmData form
Add a button to run the import
macro
Click on it
Observe that the tables in your
database are updated!
20 Access - Using Macros Factory
44. Updated Data Form
21 Access - Using Macros Factory
New Tables after Running Macro
22 Access - Using Macros Factory
45. Custom Key Assignments
Key combination goes in macro name field
Use Send Keys codes to create the macro
Can have conditions if desired, too
23 Access - Using Macros Factory
Create Import/Export AutoKeys
24 Access - Using Macros Factory
46. Automating Startup
Put VBA code in the form Open and/or Load
event, or
Use a startup (old DOS autoexec concept)
macro
– Create a macro with the name Autoexec – it will
“fire” when your app starts. Hold down the shift key
to bypass it.
25 Access - Using Macros Factory
Autoexec Macro
26 Access - Using Macros Factory
47. Create an AutoExec Macro
Modify your import/export macro
Keep the import part only
Save as autoexec
Delete your linked tables and the labor import
Close and restart your database – notice the
tables were added again automatically
27 Access - Using Macros Factory
Setting a Value
Set value can be used to do calculations, etc.
Two action arguments
– The item that will have its value set
– The expression to put in
28 Access - Using Macros Factory
48. First Add an Overhead Control
Add an unbound text box to the
frmwork_OrdersMacro form
Call it txtOverhead
29 Access - Using Macros Factory
Form with Overhead Control
30 Access - Using Macros Factory
49. Create Set Value Macro
31 Access - Using Macros Factory
Item to set
32 Access - Using Macros Factory
50. Value Expression
33 Access - Using Macros Factory
Invoke the Macro
Use the form’s on current event
This fires whenever we move to a new record
When the event fires run the macro
34 Access - Using Macros Factory
51. Invoke the Macro
Note: this
Is a form event
35 Access - Using Macros Factory
Using the Macro
36 Access - Using Macros Factory
52. Using Set Value
Update frmData_Macro with two new
controls…
– Checkbox which says wether or not to hide the work
order selection text box
– Textbox for work order
Add a macro which will hide and show the
above text box
37 Access - Using Macros Factory
Adding the Macro
38 Access - Using Macros Factory
53. Item to Set
39 Access - Using Macros Factory
Value Expression to Hide/Unhide
40 Access - Using Macros Factory
54. Form with New Controls
41 Access - Using Macros Factory
Data Macros
Data macros fire when a certain event takes
place within a table – similar to a trigger in
Oracle or SQL Server
– After insert
– After update
– Etc.
42 Access - Using Macros Factory
55. Data Macros
Add an overtime rate field to the employees
table
Add a data macro to update this field when the
regular time rate changes
43 Access - Using Macros Factory
Data Macros
44 Access - Using Macros Factory
56. Before Change Macro
45 Access - Using Macros Factory
Table with Data Macro
46 Access - Using Macros Factory
57. Macros to Code
Can convert macros to VBA code
A handy way to get your VBA subroutine
started
In general, programmers will use code, not
macros
But as we have seen Macros can be quite
handy
47 Access - Using Macros Factory
Macros to Code
48 Access - Using Macros Factory
58. Macro to Code
49 Access - Using Macros Factory
Add a Close Button
Open frmData_Macro in design
mode
Add a close form button
Select close form from
operations
Run the form
That’s it!
50 Access - Using Macros Factory
59. Final Data Macro Form
51 Access - Using Macros Factory
Microsoft Access
End of Module
P.O. Box 6142 Please fill out and turn in your
Laguna Niguel, CA 92607
949-489-1472 end-of-course evaluations if
http://www.d2associates.com this is your last module
52 Factory Access - Using Macros
60. Microsoft Access
Module – Navigation
P.O. Box 6142
Laguna Niguel, CA 92607
949-489-1472
http://www.d2associates.com
1 Factory Access Navigation
Access navigation
Newer Access 2010 databases use the new
Navigation forms
Older MDB databases still have the
Switchboard Manager tool available
2 Access Navigation Factory
61. Creating a Navigation form
Select the desired style
3 Access Navigation Factory
Navigation Forms
Drag and drop forms and reports one by one
4 Access Navigation Factory
62. Adjust properties
Adjust properties as desired and save as
frmNavigation
5 Access Navigation Factory
Set startup options (File | Options)
Set the Access options to open the navigation
form when it starts up
6 Access Navigation Factory
63. Navigation Form
Create a navigation form for
your application
7 Access Navigation Factory
Switchboards
Create via a switchboard manager tool
Creates a tree of launch forms – main
form is called switchboard and is placed
with your other form objects
8 Access Navigation Factory
64. Launching Switchboard Manager
9 Access Navigation Factory
Switchboard Manager
Yes – we want to create a new switchboard!
10 Access Navigation Factory
65. Switchboard Manager
11 Access Navigation Factory
Switchboards
Create a switchboard for your
application
12 Access Navigation Factory
66. Add a macro to minimize database
window
Create macro (add to mcrForm macro group)
Invoke on form load of switchboard form
13 Access Switchboards Factory
Updated mcrForm
14 Access Switchboards Factory
67. Add to main switchboard load
event
15 Access Switchboards Factory
Switchboard test
Close your database
Reopen your database – the database window
should be minimized
16 Access Switchboards Factory
68. Microsoft Access
End of Module
P.O. Box 6142
Laguna Niguel, CA 92607
Please fill out and turn in your
949-489-1472 end-of-course evaluations.
http://www.d2associates.com
17 Factory Access Navigation
Notes
18 Access Navigation Factory
70. Orange Coast Database Associates Course (800)355-9855 or http://ocdatabases.itgo.com
Accelerated Computer Training
Orange Coast
Database Associates
Specializing in Microsoft Office,
Access, SQL, and related technologies
Computer Training, Programming & Consulting
32422 Alipaz St., Suite A-15
San Juan Capistrano, CA
(800)355-9855 (Toll Free) | (949)489-1472 (Direct) | (949)485-6284 (Fax)
http://www.dhdursoassociates.com | sales@dhdursoassociates.com
Accelerated Computer Training for Working Professionals