SlideShare a Scribd company logo
1 of 14
Download to read offline
By Paul Barnett




       1
Beginning Access Database Macros ............................................................... 3
    What is an Access macro? ....................................................................... 3
    The macro designer .................................................................................. 4
    Creating our first macro ............................................................................ 6
    A macro to filter a form by a value ............................................................ 6
    Create a macro to copy and back up an object....................................... 10




                   Get the Full Version of This E-book

                  http://www.access-databases.com/ebooks/macros/




                                                    2
Beginning Access Database Macros


For beginners of Microsoft Access databases VBA programming can be a
daunting task. Fortunately Access offers an alternative in the shape of
macros.


What is an Access macro?

A macro can best be thought of as an action or group of actions which can
perform a database related operation. For example we can create a macro for
opening a form, printing a report or automating many other tasks.

We can create a single macro containing a set of actions or a macro group.
We can also add conditions to our macros in order to provide greater
flexibility.

One complaint of MS Access macros has always been that they do not have
any error checking. This is not now an issue with newer versions of Access –
2007 onwards.

Another issue is that if a macro fails it does not offer a good enough
explanation. We get the standard Access macro error messages and cannot
add our own.




Apart from the issues mentioned, Access macros enable us to create some
powerful functionality.

This guide will enable you to get started and experience the power of MS
Access macros.


                                      3
The macro designer

Let’s create a new macro.

Go to the database window and select the ‘Macros’ option.




Now select the new option.




You will now see the macro designer window.




                                     4
There are 3 columns shown

      Macro Name
      Action
      Comment

You can also add another column by going up to the view menu and selecting
conditions.




So now you get




Let’s now go over what each column is used for.

Macro Name
As the title suggests this is where we give the macro a descriptive name.

Condition
This is where you specify what conditions the macro needs to meet when
executed. For example a condition could be - does the order have an order
number? If it does, then execute the macro actions.

Action
This is the macro task to be performed. For example ‘CopyObject’ will copy an
object such as a table or query to the current or another database.

Comment
A description of what the macro actually does. This is optional, but can be
handy for a new developer working on an existing system.




                                       5
Creating our first macro


A macro to filter a form by a value

I have created and saved a query which filters records on my form by country.
The country is set to Germany.




I have called the query ‘Country Filter’.




                                        6
Back at the macro designer window.

In the macro name section I have typed in ‘CountryFilter’.




I am not adding anything in the condition section.

In the action section I select the ‘ApplyFilter’ action.




This brings up some properties at the bottom of the macro window.




In filter name I now enter the name of the saved query.




Save the macro as ‘Macro1’.

Close the macro designer window.




                                          7
On my form I create a new command button using the wizard.

I select the miscellaneous category and the run macro action.




I now select the macro I want to use behind the button.

Notice it gives the macro name and the action within it.




                                       8
So now I have wired up my macro to a button on a form.

When the button is clicked my macro will fire and will apply a filter to the form
for all records in Germany.




We have our Macro1 saved which applies the filter.




We could set up more macros and call them Macro2,3,4,5 etc. However, it is
better to set up a macro group to hold more than one macro. Each one is
identified and called by name.




                                        9
Create a macro to copy and back up an object

I am now going to use the ‘CopyObject’ macro action.

This action will copy objects such as tables and queries to the same or
another database.

I select the original macro I used and go into design mode again.
Under the macro name column I enter a new macro name ‘BackUpObject’.
I also select the ‘CopyObject’ macro action.




At the bottom of the window I set the following:




Destination database is where I want the object saved. I enter a path here to
the database.

New name is any new name I want to give to this object. As I am making a
backup in another database I called it ‘Customers_BK’.

In the source object type tell it the type of object you are selecting. In this case
my type is a table.

The source object name will be the current name of the object in the
database. In this case it is my customers table.

You may also want to back up additional tables. The procedure would be the
same. Just add more ‘CopyObject’ actions to this group.




                                        10
I’ve also added my orders table in, so now I have two ‘CopyObject’ actions.




I’ve also added a message box action to display a message when the
operation is complete.




The message I want displayed is ‘Backup is complete’.

I now save and run the macro.


                                     11
I create a simple form with a command button.




Right click on the button and select ‘Build Event’.




Now select code builder and click ok.




The code window will appear.

My procedure looks like the following.

Private Sub Command0_Click()
   DoCmd.RunMacro ("Macro1.BackupObject")
End Sub




                                         12
The line that calls the macro is

DoCmd.RunMacro ("Macro1.BackupObject")

Macro1 is the name of the saved macro shown in the database window.
BackupObject is the name of the group inside the macro1 that contains the
actions.

The other groups will not be run, only the one referred to in the code above.

When the macro has finished running the message specified in the macro is
displayed.




And in my external database the tables have been saved.

      Customers_BK

      Orders_BK




Objects such as forms and reports can also be copied by using the
‘CopyObject’ action.




                                      13
Get the Full Version of This E-book

http://www.access-databases.com/ebooks/macros/




      2010 Paul Barnett. All Rights Reserved.
     No part of this publication may be reprinted
         or reproduced without permission.




                         14

More Related Content

What's hot

Manual de macros en calc
Manual de macros en calcManual de macros en calc
Manual de macros en calcBerthamazon
 
Micro station v8 manual
Micro station v8 manualMicro station v8 manual
Micro station v8 manualyuri30
 
E learning excel vba programming lesson 1
E learning excel vba programming  lesson 1E learning excel vba programming  lesson 1
E learning excel vba programming lesson 1Vijay Perepa
 
Top 10 Excel Beginner Basics
Top 10 Excel Beginner BasicsTop 10 Excel Beginner Basics
Top 10 Excel Beginner BasicsWiley
 
MS EXCEL PPT PRESENTATION
MS EXCEL PPT PRESENTATIONMS EXCEL PPT PRESENTATION
MS EXCEL PPT PRESENTATIONMridul Bansal
 
Adv excel® 2013
Adv excel® 2013Adv excel® 2013
Adv excel® 2013Raghu nath
 
Module 8: Grade Center Task 2
Module 8: Grade Center Task 2Module 8: Grade Center Task 2
Module 8: Grade Center Task 2Ciel Educttu
 
E learning excel vba programming lesson 2
E learning excel vba programming  lesson 2E learning excel vba programming  lesson 2
E learning excel vba programming lesson 2Vijay Perepa
 
Quick Guide to Get Started with ShoutOUT V4.0
Quick Guide to Get Started with ShoutOUT V4.0 Quick Guide to Get Started with ShoutOUT V4.0
Quick Guide to Get Started with ShoutOUT V4.0 Tharindu Dassanayake
 
An Interactive Dashboard - Part 2
An Interactive Dashboard - Part 2An Interactive Dashboard - Part 2
An Interactive Dashboard - Part 2Pranav Ghode
 
Module 6: Assignments Task 3
Module 6: Assignments Task 3Module 6: Assignments Task 3
Module 6: Assignments Task 3Ciel Educttu
 
Fix adobe-flash-player-crashes
Fix adobe-flash-player-crashesFix adobe-flash-player-crashes
Fix adobe-flash-player-crashesVikas Medhekar
 
Creating a quiz using visual basic 6
Creating a quiz using visual basic 6Creating a quiz using visual basic 6
Creating a quiz using visual basic 6Ella Marie Wico
 

What's hot (20)

Excel review and view tab
Excel review and view tabExcel review and view tab
Excel review and view tab
 
VBA Tips
VBA TipsVBA Tips
VBA Tips
 
Manual de macros en calc
Manual de macros en calcManual de macros en calc
Manual de macros en calc
 
Micro station v8 manual
Micro station v8 manualMicro station v8 manual
Micro station v8 manual
 
E learning excel vba programming lesson 1
E learning excel vba programming  lesson 1E learning excel vba programming  lesson 1
E learning excel vba programming lesson 1
 
Top 10 Excel Beginner Basics
Top 10 Excel Beginner BasicsTop 10 Excel Beginner Basics
Top 10 Excel Beginner Basics
 
Visual basic
Visual basicVisual basic
Visual basic
 
MS EXCEL PPT PRESENTATION
MS EXCEL PPT PRESENTATIONMS EXCEL PPT PRESENTATION
MS EXCEL PPT PRESENTATION
 
Adv excel® 2013
Adv excel® 2013Adv excel® 2013
Adv excel® 2013
 
Excel® 2013
Excel® 2013Excel® 2013
Excel® 2013
 
Module 8: Grade Center Task 2
Module 8: Grade Center Task 2Module 8: Grade Center Task 2
Module 8: Grade Center Task 2
 
Tutorials3
Tutorials3Tutorials3
Tutorials3
 
Excel 2013
Excel 2013Excel 2013
Excel 2013
 
E learning excel vba programming lesson 2
E learning excel vba programming  lesson 2E learning excel vba programming  lesson 2
E learning excel vba programming lesson 2
 
Quick Guide to Get Started with ShoutOUT V4.0
Quick Guide to Get Started with ShoutOUT V4.0 Quick Guide to Get Started with ShoutOUT V4.0
Quick Guide to Get Started with ShoutOUT V4.0
 
An Interactive Dashboard - Part 2
An Interactive Dashboard - Part 2An Interactive Dashboard - Part 2
An Interactive Dashboard - Part 2
 
Module 6: Assignments Task 3
Module 6: Assignments Task 3Module 6: Assignments Task 3
Module 6: Assignments Task 3
 
Web Server Controls CS Set
Web Server Controls CS Set Web Server Controls CS Set
Web Server Controls CS Set
 
Fix adobe-flash-player-crashes
Fix adobe-flash-player-crashesFix adobe-flash-player-crashes
Fix adobe-flash-player-crashes
 
Creating a quiz using visual basic 6
Creating a quiz using visual basic 6Creating a quiz using visual basic 6
Creating a quiz using visual basic 6
 

Viewers also liked

Viewers also liked (11)

Macros
MacrosMacros
Macros
 
Macros
MacrosMacros
Macros
 
Formularios en microsoft access
Formularios en microsoft accessFormularios en microsoft access
Formularios en microsoft access
 
Biblia De Access 2007
Biblia De Access 2007Biblia De Access 2007
Biblia De Access 2007
 
Ms Access
Ms AccessMs Access
Ms Access
 
Tipo de consulta microsoft access
Tipo de consulta microsoft accessTipo de consulta microsoft access
Tipo de consulta microsoft access
 
tablas en acces
tablas en accestablas en acces
tablas en acces
 
Introduction to microsoft access
Introduction to microsoft accessIntroduction to microsoft access
Introduction to microsoft access
 
Ejercicios paso a paso access
Ejercicios paso a paso accessEjercicios paso a paso access
Ejercicios paso a paso access
 
Ms access
Ms accessMs access
Ms access
 
Ms Access ppt
Ms Access pptMs Access ppt
Ms Access ppt
 

Similar to MS Access Macros

AIA101.4.Automating Access
AIA101.4.Automating AccessAIA101.4.Automating Access
AIA101.4.Automating AccessDan D'Urso
 
VBA for technical writers
VBA for technical writersVBA for technical writers
VBA for technical writersTCUK
 
Generic Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkGeneric Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkAkhil Mittal
 
Learn Vba excel 2007
Learn Vba excel 2007Learn Vba excel 2007
Learn Vba excel 2007Steve Johnson
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLAkhil Mittal
 
Informatica object migration
Informatica object migrationInformatica object migration
Informatica object migrationAmit Sharma
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkAkhil Mittal
 
Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1rupeshkanu
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010vchircu
 
Repository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkRepository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkAkhil Mittal
 

Similar to MS Access Macros (20)

Using macros in microsoft access
Using macros in microsoft accessUsing macros in microsoft access
Using macros in microsoft access
 
AIA101.4.Automating Access
AIA101.4.Automating AccessAIA101.4.Automating Access
AIA101.4.Automating Access
 
007.macro
007.macro007.macro
007.macro
 
VBA
VBAVBA
VBA
 
VBA
VBAVBA
VBA
 
Malab tutorial
Malab tutorialMalab tutorial
Malab tutorial
 
VBA for technical writers
VBA for technical writersVBA for technical writers
VBA for technical writers
 
Macros
MacrosMacros
Macros
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
 
Generic Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkGeneric Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity Framework
 
Learn Vba excel 2007
Learn Vba excel 2007Learn Vba excel 2007
Learn Vba excel 2007
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
 
Informatica object migration
Informatica object migrationInformatica object migration
Informatica object migration
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFramework
 
Well You Ought To Know (WYOTK) FP&A Automation Series
Well You Ought To Know (WYOTK) FP&A Automation SeriesWell You Ought To Know (WYOTK) FP&A Automation Series
Well You Ought To Know (WYOTK) FP&A Automation Series
 
Mac2
Mac2Mac2
Mac2
 
Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
Repository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkRepository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity Framework
 
Remedy Presentation
Remedy PresentationRemedy Presentation
Remedy Presentation
 

Recently uploaded

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 

Recently uploaded (20)

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 

MS Access Macros

  • 2. Beginning Access Database Macros ............................................................... 3 What is an Access macro? ....................................................................... 3 The macro designer .................................................................................. 4 Creating our first macro ............................................................................ 6 A macro to filter a form by a value ............................................................ 6 Create a macro to copy and back up an object....................................... 10 Get the Full Version of This E-book http://www.access-databases.com/ebooks/macros/ 2
  • 3. Beginning Access Database Macros For beginners of Microsoft Access databases VBA programming can be a daunting task. Fortunately Access offers an alternative in the shape of macros. What is an Access macro? A macro can best be thought of as an action or group of actions which can perform a database related operation. For example we can create a macro for opening a form, printing a report or automating many other tasks. We can create a single macro containing a set of actions or a macro group. We can also add conditions to our macros in order to provide greater flexibility. One complaint of MS Access macros has always been that they do not have any error checking. This is not now an issue with newer versions of Access – 2007 onwards. Another issue is that if a macro fails it does not offer a good enough explanation. We get the standard Access macro error messages and cannot add our own. Apart from the issues mentioned, Access macros enable us to create some powerful functionality. This guide will enable you to get started and experience the power of MS Access macros. 3
  • 4. The macro designer Let’s create a new macro. Go to the database window and select the ‘Macros’ option. Now select the new option. You will now see the macro designer window. 4
  • 5. There are 3 columns shown  Macro Name  Action  Comment You can also add another column by going up to the view menu and selecting conditions. So now you get Let’s now go over what each column is used for. Macro Name As the title suggests this is where we give the macro a descriptive name. Condition This is where you specify what conditions the macro needs to meet when executed. For example a condition could be - does the order have an order number? If it does, then execute the macro actions. Action This is the macro task to be performed. For example ‘CopyObject’ will copy an object such as a table or query to the current or another database. Comment A description of what the macro actually does. This is optional, but can be handy for a new developer working on an existing system. 5
  • 6. Creating our first macro A macro to filter a form by a value I have created and saved a query which filters records on my form by country. The country is set to Germany. I have called the query ‘Country Filter’. 6
  • 7. Back at the macro designer window. In the macro name section I have typed in ‘CountryFilter’. I am not adding anything in the condition section. In the action section I select the ‘ApplyFilter’ action. This brings up some properties at the bottom of the macro window. In filter name I now enter the name of the saved query. Save the macro as ‘Macro1’. Close the macro designer window. 7
  • 8. On my form I create a new command button using the wizard. I select the miscellaneous category and the run macro action. I now select the macro I want to use behind the button. Notice it gives the macro name and the action within it. 8
  • 9. So now I have wired up my macro to a button on a form. When the button is clicked my macro will fire and will apply a filter to the form for all records in Germany. We have our Macro1 saved which applies the filter. We could set up more macros and call them Macro2,3,4,5 etc. However, it is better to set up a macro group to hold more than one macro. Each one is identified and called by name. 9
  • 10. Create a macro to copy and back up an object I am now going to use the ‘CopyObject’ macro action. This action will copy objects such as tables and queries to the same or another database. I select the original macro I used and go into design mode again. Under the macro name column I enter a new macro name ‘BackUpObject’. I also select the ‘CopyObject’ macro action. At the bottom of the window I set the following: Destination database is where I want the object saved. I enter a path here to the database. New name is any new name I want to give to this object. As I am making a backup in another database I called it ‘Customers_BK’. In the source object type tell it the type of object you are selecting. In this case my type is a table. The source object name will be the current name of the object in the database. In this case it is my customers table. You may also want to back up additional tables. The procedure would be the same. Just add more ‘CopyObject’ actions to this group. 10
  • 11. I’ve also added my orders table in, so now I have two ‘CopyObject’ actions. I’ve also added a message box action to display a message when the operation is complete. The message I want displayed is ‘Backup is complete’. I now save and run the macro. 11
  • 12. I create a simple form with a command button. Right click on the button and select ‘Build Event’. Now select code builder and click ok. The code window will appear. My procedure looks like the following. Private Sub Command0_Click() DoCmd.RunMacro ("Macro1.BackupObject") End Sub 12
  • 13. The line that calls the macro is DoCmd.RunMacro ("Macro1.BackupObject") Macro1 is the name of the saved macro shown in the database window. BackupObject is the name of the group inside the macro1 that contains the actions. The other groups will not be run, only the one referred to in the code above. When the macro has finished running the message specified in the macro is displayed. And in my external database the tables have been saved.  Customers_BK  Orders_BK Objects such as forms and reports can also be copied by using the ‘CopyObject’ action. 13
  • 14. Get the Full Version of This E-book http://www.access-databases.com/ebooks/macros/  2010 Paul Barnett. All Rights Reserved. No part of this publication may be reprinted or reproduced without permission. 14