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

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

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