SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Automating Tasks
  with Macros
Macro Essentials
 A macro is a list of actions that happen when
  you run the macro.
 Creating a Macro:
 − Choose Create  Macros & Code  Macro.
 − Choose first action in the Add New Action list.
 − Fill in the arguments for your action, using the
   text boxes that appear under it.
Macro Essentials
 Running a Macro: there are four ways to run a
  macro.
 − Run it directly by double-click its name in
   Navigation pane, Or, if the macro is open,
   choose Macro Tools | Design  Tools  Run.
 − Can trigger it using a keystroke.
 − Run it automatically when the database is first
   opened.
 − Attach macro to a form.
Editing a Macro
 Open macro in Design view
 − Change action arguments.
 − Reorder actions.
 − Add a new action.
 − Remove an action.
 − Add comments.
Collapsing, Expanding, and
Grouping Macro Actions
 Collapsing, Expanding: by simply clicking the
  +/– button that appears to the left of the action
  name.
 − Collapsing: hide some of this information.
 − Expanding: Expand the action back into view.
 Grouping Macro Actions: subdivide a single
  macro in sections that help you concentrate on
  the portion of the macro that interests you.
Collapsing, Expanding, and
Grouping Macro Actions
 To create a group:
 − In the Add New Action list, choose Group. It’s
   the second entry.
 − Enter a group name.
 − Add actions to your group.
   Every group starts with the group name and
     ends with the text “End Group”. In between
     are the actions of the group.
Collapsing, Expanding, and
Grouping Macro Actions
 Example:
Solving Macro Problems
 These steps to use single-step debugging:
 − Open macro in Design view.
 − Choose Macro Tools | Design ➝ Tools 
   Single Step.
 − Choose Macro Tools | Design ➝ Tools ➝ Run
 − Click Step, Continue, or Stop All Macros,
   depending on what you want to do next.
Managing Macros
 To manage macros, can use the sub macro
  feature.
 − A sub macro is a small, named bundle of
    actions.
 − The nifty of sub macros is can put many sub
    macros into a single macro object.
 − Using sub macros, you can keep related
    functionality close together, easier time
    finding the macro you need.
Managing Macros
 To create sub macros:
 − Opening an existing macro
 − Choose Sub macro from the Add New Action
   list.
 − Or drag the Program Flow ➝ Sub macro
   action from the Action Catalog and drop it
   onto your macro
 − Either way create a new blank sub macro.
Managing Macros
 Two ways to add a Sub macro:
Configuring a Startup Macro
 Macro AutoExec:
 − Macro automatically run when open database
 − Macro always include the actions like:
   Opens a few important forms and reports.
   Imports data from another file.
   Runs a cleanup query.
 − Macro name is AutoExec
Connecting Macros to
Forms and Tables
 Understanding Events: A form has three types
  of events:
 − Control events: These events are the most
   useful. They happen when you do something
   with a control.
 − Section events: forms are divided into
   sections, each section has its own events.
 − Form events: includes events that fire when
   the form is opened, closed, when move from
   one record to the next and an update.
Connecting Macros to
Forms and Tables
To see the list of events for a
 form’s different parts:
 − Open your form in Design
   mode.
 − Select the item that has the
   events     you    want    to
   examine.
 − In the Property Sheet,
   choose the Event tab.
 − Select event appropriate.
Attaching a Macro to an Event
Create and save a macro.
Open form in Design view, and
 make sure the Property Sheet
 is visible.
Select a control, a section, or
 the entire form.
In the Property Sheet, choose
 the Events tab, and then find
 the event you want to use.
In the Event box, click the
 drop-down arrow, and choose
 the macro you want to use.
Conditional Macros
 Conditional   Macros:    perform   conditional
  actions.
 − To create a conditional macro, need to use the
    If action:
    Select the If action from the Add New
       Action list
    Drag If action from the Program Flow
       section of the Action Catalog.
 − The If action requires a single argument,
    which is a condition.
Conditional Macros
 Here’s how it works:
 − If the condition turns out to be True, Access
   runs the actions in the If box.
 − If the condition turns out to be False, Access
   skips over the actions in the If box and
   continues with the next action after the If
   action.
Conditional Macros
 Building a Condition:
 − Use the compare operators: <, > <=, >=, <>, =
 − Logical operator: And & Or.
 − Functions:
    IsNull()
    Len()
    …
Data Macros
 Data Macros is a macro run when an event
  occurs in a table.
 Data macros respond to table events like create
  a record, edit a record, and send an email.
 Data macros support a different set of actions.
 Data macros can stick with database even when
  transfer it to another platform.
Data Macros
    Table Events:
Event           Description

              Occurs just before Access commits an edit or inserts a new
              record. If you need to distinguish between the two, you can
Before Change create conditions that use the IsInsert property, which is True
              for inserts and False for updates.

Before Delete   Occurs just before Access removes a record from a table

After Insert    Occurs after Access has finished inserting a new record.
                Occurs after Access has finished updating a record after an
After Update
                edit.
                Occurs after Access has removed a deleted record from the
After Delete
                table.
Data Macros
 Example: Create a data macro that prevents a
  blank value for EmailAddress:
 − Open table in Datasheet view.
 − Choose Table Tools  Table  Before Events
     Before Change.
 − Add the actions you need:
    If action tests to see if the rules are being
      broken.
   [WantsEmail]=Yes And IsNull([EmailAddress]).
    RaiseError action cancels the change and
      provides an error message.

Weitere ähnliche Inhalte

Andere mochten auch

Chap014 retention management_editing
Chap014 retention management_editingChap014 retention management_editing
Chap014 retention management_editing
Zilafeeq Shafilla
 
STAFFING 1
STAFFING 1STAFFING 1
STAFFING 1
Joe
 
Gender presentation
Gender presentationGender presentation
Gender presentation
Sydni Powell
 

Andere mochten auch (20)

flash
flashflash
flash
 
Dustin's project
Dustin's projectDustin's project
Dustin's project
 
Chap014 retention management_editing
Chap014 retention management_editingChap014 retention management_editing
Chap014 retention management_editing
 
Staffing
StaffingStaffing
Staffing
 
Staffing
StaffingStaffing
Staffing
 
Difference bw gender and sex
Difference bw gender and sexDifference bw gender and sex
Difference bw gender and sex
 
Sex and Gender: What is the difference?
Sex and Gender: What is the difference?Sex and Gender: What is the difference?
Sex and Gender: What is the difference?
 
Womens Studies Chapter 1 Powerpoint
Womens Studies Chapter 1 PowerpointWomens Studies Chapter 1 Powerpoint
Womens Studies Chapter 1 Powerpoint
 
Women and Gender Studies - an Overview
Women and Gender Studies - an OverviewWomen and Gender Studies - an Overview
Women and Gender Studies - an Overview
 
Principles of Management Chapter 5 Staffing
Principles of Management Chapter 5 StaffingPrinciples of Management Chapter 5 Staffing
Principles of Management Chapter 5 Staffing
 
IV Gender Studies
IV Gender StudiesIV Gender Studies
IV Gender Studies
 
STAFFING 1
STAFFING 1STAFFING 1
STAFFING 1
 
Introduction to Women's and Gender Studies Lecture
Introduction to Women's and Gender Studies LectureIntroduction to Women's and Gender Studies Lecture
Introduction to Women's and Gender Studies Lecture
 
Unit 5 staffing
Unit 5 staffingUnit 5 staffing
Unit 5 staffing
 
Gender presentation
Gender presentationGender presentation
Gender presentation
 
Lecture 11 - Sex and Gender
Lecture 11 -  Sex and GenderLecture 11 -  Sex and Gender
Lecture 11 - Sex and Gender
 
Sex and Gender Roles
Sex and Gender RolesSex and Gender Roles
Sex and Gender Roles
 
Gender Differences PowerPoint PPT Content Modern Sample
Gender Differences PowerPoint PPT Content Modern SampleGender Differences PowerPoint PPT Content Modern Sample
Gender Differences PowerPoint PPT Content Modern Sample
 
GENDER DIFFERENCES POWERPOINT
GENDER DIFFERENCES POWERPOINT GENDER DIFFERENCES POWERPOINT
GENDER DIFFERENCES POWERPOINT
 
Nature of Staffing
Nature of Staffing Nature of Staffing
Nature of Staffing
 

Ähnlich wie 007.macro

GEIT 3341 DATABASE I LAB 2 GEIT 3341 Database I
GEIT 3341  DATABASE I  LAB 2  GEIT 3341 Database I  GEIT 3341  DATABASE I  LAB 2  GEIT 3341 Database I
GEIT 3341 DATABASE I LAB 2 GEIT 3341 Database I
MatthewTennant613
 
7200342 cognos-report-studio
7200342 cognos-report-studio7200342 cognos-report-studio
7200342 cognos-report-studio
sarovar1
 
Unit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptxUnit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptx
ShantanuDharekar
 

Ähnlich wie 007.macro (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
 
MS Access Macros
MS Access MacrosMS Access Macros
MS Access Macros
 
VBA Tips
VBA TipsVBA Tips
VBA Tips
 
MicroStrategy Basic Reporting.pptx
MicroStrategy Basic Reporting.pptxMicroStrategy Basic Reporting.pptx
MicroStrategy Basic Reporting.pptx
 
Joomla 3 installation and management guide
Joomla 3 installation and management guideJoomla 3 installation and management guide
Joomla 3 installation and management guide
 
Remedy Presentation
Remedy PresentationRemedy Presentation
Remedy Presentation
 
Lab3-Android
Lab3-AndroidLab3-Android
Lab3-Android
 
Installing and Using Productivity Shortcuts
Installing and Using Productivity ShortcutsInstalling and Using Productivity Shortcuts
Installing and Using Productivity Shortcuts
 
How To Automate Part 3
How To Automate Part 3How To Automate Part 3
How To Automate Part 3
 
GEIT 3341 DATABASE I LAB 2 GEIT 3341 Database I
GEIT 3341  DATABASE I  LAB 2  GEIT 3341 Database I  GEIT 3341  DATABASE I  LAB 2  GEIT 3341 Database I
GEIT 3341 DATABASE I LAB 2 GEIT 3341 Database I
 
7200342 cognos-report-studio
7200342 cognos-report-studio7200342 cognos-report-studio
7200342 cognos-report-studio
 
Understanding Microsoft Access
Understanding Microsoft AccessUnderstanding Microsoft Access
Understanding Microsoft Access
 
Macros
MacrosMacros
Macros
 
Learning Robotic Process Automation-81-167
Learning Robotic Process Automation-81-167Learning Robotic Process Automation-81-167
Learning Robotic Process Automation-81-167
 
Login methodology for Primavera V8.3 (EPPM)
Login methodology for Primavera V8.3 (EPPM)Login methodology for Primavera V8.3 (EPPM)
Login methodology for Primavera V8.3 (EPPM)
 
Ch06 cmpt110
Ch06 cmpt110Ch06 cmpt110
Ch06 cmpt110
 
First steps with Scilab
First steps with ScilabFirst steps with Scilab
First steps with Scilab
 
IBM Maximo Tips & Tricks
IBM Maximo Tips & TricksIBM Maximo Tips & Tricks
IBM Maximo Tips & Tricks
 
Unit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptxUnit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptx
 

Mehr von Học Huỳnh Bá

Từ vựng chuyên ngành sản xuất giày da (tiếng trung việt) 鞋类常见词汇(汉语 - 越南语)
Từ vựng chuyên ngành sản xuất giày da (tiếng trung   việt) 鞋类常见词汇(汉语 - 越南语)Từ vựng chuyên ngành sản xuất giày da (tiếng trung   việt) 鞋类常见词汇(汉语 - 越南语)
Từ vựng chuyên ngành sản xuất giày da (tiếng trung việt) 鞋类常见词汇(汉语 - 越南语)
Học Huỳnh Bá
 
Useful vocabulary for the resume and interview 英文简历及面试有用词汇 danh mục từ vựng a...
Useful vocabulary for the resume and interview 英文简历及面试有用词汇 danh mục từ vựng a...Useful vocabulary for the resume and interview 英文简历及面试有用词汇 danh mục từ vựng a...
Useful vocabulary for the resume and interview 英文简历及面试有用词汇 danh mục từ vựng a...
Học Huỳnh Bá
 

Mehr von Học Huỳnh Bá (20)

BÀI GIẢNG NGỮ PHÁP TIẾNG ANH NGÀNH GIA CÔNG SẢN XUẤT
BÀI GIẢNG NGỮ PHÁP TIẾNG ANH NGÀNH GIA CÔNG SẢN XUẤTBÀI GIẢNG NGỮ PHÁP TIẾNG ANH NGÀNH GIA CÔNG SẢN XUẤT
BÀI GIẢNG NGỮ PHÁP TIẾNG ANH NGÀNH GIA CÔNG SẢN XUẤT
 
Civil aviation english chinese-vietnamese vocabulary (popular language) - từ ...
Civil aviation english chinese-vietnamese vocabulary (popular language) - từ ...Civil aviation english chinese-vietnamese vocabulary (popular language) - từ ...
Civil aviation english chinese-vietnamese vocabulary (popular language) - từ ...
 
Tell about a girl boy that you interested in
Tell about a girl boy that you interested inTell about a girl boy that you interested in
Tell about a girl boy that you interested in
 
Thư xin đi xe đón nhân viên shuttle transport service proposal letter (chine...
Thư xin đi xe đón nhân viên shuttle transport service proposal  letter (chine...Thư xin đi xe đón nhân viên shuttle transport service proposal  letter (chine...
Thư xin đi xe đón nhân viên shuttle transport service proposal letter (chine...
 
Từ vựng chuyên ngành sản xuất giày da (tiếng trung việt) 鞋类常见词汇(汉语 - 越南语)
Từ vựng chuyên ngành sản xuất giày da (tiếng trung   việt) 鞋类常见词汇(汉语 - 越南语)Từ vựng chuyên ngành sản xuất giày da (tiếng trung   việt) 鞋类常见词汇(汉语 - 越南语)
Từ vựng chuyên ngành sản xuất giày da (tiếng trung việt) 鞋类常见词汇(汉语 - 越南语)
 
Common shoe and footwear vocabulary (english chinese-vietnamese)鞋类常见词汇(英语、汉语、...
Common shoe and footwear vocabulary (english chinese-vietnamese)鞋类常见词汇(英语、汉语、...Common shoe and footwear vocabulary (english chinese-vietnamese)鞋类常见词汇(英语、汉语、...
Common shoe and footwear vocabulary (english chinese-vietnamese)鞋类常见词汇(英语、汉语、...
 
Chinese email 高职高专院校英语能力测试a b级
Chinese email  高职高专院校英语能力测试a b级Chinese email  高职高专院校英语能力测试a b级
Chinese email 高职高专院校英语能力测试a b级
 
English chinese business languages bec中级写作电子讲义
English   chinese business languages bec中级写作电子讲义English   chinese business languages bec中级写作电子讲义
English chinese business languages bec中级写作电子讲义
 
Chinese english writing skill - 商务写作教程
Chinese english writing skill  - 商务写作教程Chinese english writing skill  - 商务写作教程
Chinese english writing skill - 商务写作教程
 
Giấy báo thay đổi hộ khẩu, nhân khẩu
Giấy báo thay đổi hộ khẩu, nhân khẩuGiấy báo thay đổi hộ khẩu, nhân khẩu
Giấy báo thay đổi hộ khẩu, nhân khẩu
 
祈福英语实验学校入学申请表 Clifford school application form
祈福英语实验学校入学申请表 Clifford school application form祈福英语实验学校入学申请表 Clifford school application form
祈福英语实验学校入学申请表 Clifford school application form
 
LIST OF CHINESE & VIETNAMESE COLOR NAMES 表示颜色的英语&越南语词汇 DANH MỤC TỪ VỰNG VỀ MÀ...
LIST OF CHINESE & VIETNAMESE COLOR NAMES 表示颜色的英语&越南语词汇 DANH MỤC TỪ VỰNG VỀ MÀ...LIST OF CHINESE & VIETNAMESE COLOR NAMES 表示颜色的英语&越南语词汇 DANH MỤC TỪ VỰNG VỀ MÀ...
LIST OF CHINESE & VIETNAMESE COLOR NAMES 表示颜色的英语&越南语词汇 DANH MỤC TỪ VỰNG VỀ MÀ...
 
Giáo án nghiệp vụ đàm thoại tiếng anh trong nhà trường
Giáo án nghiệp vụ đàm thoại tiếng anh trong nhà trườngGiáo án nghiệp vụ đàm thoại tiếng anh trong nhà trường
Giáo án nghiệp vụ đàm thoại tiếng anh trong nhà trường
 
Giáo trình ms power point 2003
Giáo trình ms power point 2003Giáo trình ms power point 2003
Giáo trình ms power point 2003
 
Giáo trình microsoft office excel 2003
Giáo trình microsoft office excel 2003Giáo trình microsoft office excel 2003
Giáo trình microsoft office excel 2003
 
Giáo án dạy tiếng anh văn phòng
Giáo án dạy tiếng anh văn phòngGiáo án dạy tiếng anh văn phòng
Giáo án dạy tiếng anh văn phòng
 
Hợp đồng giảng dạy (mẫu)
Hợp đồng giảng dạy (mẫu)Hợp đồng giảng dạy (mẫu)
Hợp đồng giảng dạy (mẫu)
 
Bảng tham chiếu quy đổi một số chứng chỉ ngoại ngữ
Bảng tham chiếu quy đổi một số chứng chỉ ngoại ngữBảng tham chiếu quy đổi một số chứng chỉ ngoại ngữ
Bảng tham chiếu quy đổi một số chứng chỉ ngoại ngữ
 
Useful vocabulary for the resume and interview 英文简历及面试有用词汇 danh mục từ vựng a...
Useful vocabulary for the resume and interview 英文简历及面试有用词汇 danh mục từ vựng a...Useful vocabulary for the resume and interview 英文简历及面试有用词汇 danh mục từ vựng a...
Useful vocabulary for the resume and interview 英文简历及面试有用词汇 danh mục từ vựng a...
 
Bảng chữ cái hiragana
Bảng chữ cái hiraganaBảng chữ cái hiragana
Bảng chữ cái hiragana
 

007.macro

  • 1. Automating Tasks with Macros
  • 2. Macro Essentials  A macro is a list of actions that happen when you run the macro.  Creating a Macro: − Choose Create  Macros & Code  Macro. − Choose first action in the Add New Action list. − Fill in the arguments for your action, using the text boxes that appear under it.
  • 3. Macro Essentials  Running a Macro: there are four ways to run a macro. − Run it directly by double-click its name in Navigation pane, Or, if the macro is open, choose Macro Tools | Design  Tools  Run. − Can trigger it using a keystroke. − Run it automatically when the database is first opened. − Attach macro to a form.
  • 4. Editing a Macro  Open macro in Design view − Change action arguments. − Reorder actions. − Add a new action. − Remove an action. − Add comments.
  • 5. Collapsing, Expanding, and Grouping Macro Actions  Collapsing, Expanding: by simply clicking the +/– button that appears to the left of the action name. − Collapsing: hide some of this information. − Expanding: Expand the action back into view.  Grouping Macro Actions: subdivide a single macro in sections that help you concentrate on the portion of the macro that interests you.
  • 6. Collapsing, Expanding, and Grouping Macro Actions  To create a group: − In the Add New Action list, choose Group. It’s the second entry. − Enter a group name. − Add actions to your group.  Every group starts with the group name and ends with the text “End Group”. In between are the actions of the group.
  • 7. Collapsing, Expanding, and Grouping Macro Actions  Example:
  • 8. Solving Macro Problems  These steps to use single-step debugging: − Open macro in Design view. − Choose Macro Tools | Design ➝ Tools  Single Step. − Choose Macro Tools | Design ➝ Tools ➝ Run − Click Step, Continue, or Stop All Macros, depending on what you want to do next.
  • 9. Managing Macros  To manage macros, can use the sub macro feature. − A sub macro is a small, named bundle of actions. − The nifty of sub macros is can put many sub macros into a single macro object. − Using sub macros, you can keep related functionality close together, easier time finding the macro you need.
  • 10. Managing Macros  To create sub macros: − Opening an existing macro − Choose Sub macro from the Add New Action list. − Or drag the Program Flow ➝ Sub macro action from the Action Catalog and drop it onto your macro − Either way create a new blank sub macro.
  • 11. Managing Macros  Two ways to add a Sub macro:
  • 12. Configuring a Startup Macro  Macro AutoExec: − Macro automatically run when open database − Macro always include the actions like: Opens a few important forms and reports.  Imports data from another file.  Runs a cleanup query. − Macro name is AutoExec
  • 13. Connecting Macros to Forms and Tables  Understanding Events: A form has three types of events: − Control events: These events are the most useful. They happen when you do something with a control. − Section events: forms are divided into sections, each section has its own events. − Form events: includes events that fire when the form is opened, closed, when move from one record to the next and an update.
  • 14. Connecting Macros to Forms and Tables To see the list of events for a form’s different parts: − Open your form in Design mode. − Select the item that has the events you want to examine. − In the Property Sheet, choose the Event tab. − Select event appropriate.
  • 15. Attaching a Macro to an Event Create and save a macro. Open form in Design view, and make sure the Property Sheet is visible. Select a control, a section, or the entire form. In the Property Sheet, choose the Events tab, and then find the event you want to use. In the Event box, click the drop-down arrow, and choose the macro you want to use.
  • 16. Conditional Macros  Conditional Macros: perform conditional actions. − To create a conditional macro, need to use the If action:  Select the If action from the Add New Action list  Drag If action from the Program Flow section of the Action Catalog. − The If action requires a single argument, which is a condition.
  • 17. Conditional Macros  Here’s how it works: − If the condition turns out to be True, Access runs the actions in the If box. − If the condition turns out to be False, Access skips over the actions in the If box and continues with the next action after the If action.
  • 18. Conditional Macros  Building a Condition: − Use the compare operators: <, > <=, >=, <>, = − Logical operator: And & Or. − Functions:  IsNull()  Len()  …
  • 19. Data Macros  Data Macros is a macro run when an event occurs in a table.  Data macros respond to table events like create a record, edit a record, and send an email.  Data macros support a different set of actions.  Data macros can stick with database even when transfer it to another platform.
  • 20. Data Macros  Table Events: Event Description Occurs just before Access commits an edit or inserts a new record. If you need to distinguish between the two, you can Before Change create conditions that use the IsInsert property, which is True for inserts and False for updates. Before Delete Occurs just before Access removes a record from a table After Insert Occurs after Access has finished inserting a new record. Occurs after Access has finished updating a record after an After Update edit. Occurs after Access has removed a deleted record from the After Delete table.
  • 21. Data Macros  Example: Create a data macro that prevents a blank value for EmailAddress: − Open table in Datasheet view. − Choose Table Tools  Table  Before Events  Before Change. − Add the actions you need:  If action tests to see if the rules are being broken. [WantsEmail]=Yes And IsNull([EmailAddress]).  RaiseError action cancels the change and provides an error message.