SlideShare a Scribd company logo
Automating Tasks with
    Visual Basic
Introduction
 When can’t find a readymade macro action that
  does the job you want, you can use Visual Basic
  code.
 Example:
 − Modify a whole batch of records at once.
 − Perform complex calculations.
 − Interact with other programs on computer.
 − Write even more complicated validation
   routines that lock out bad data.
Understanding VBA Terminology
 Some basic VBA terminology:
 − Statement: A word or combination of words
   that constitutes an instruction to be
   performed by the VBA engine.
 − Procedure: A collection of VBA statements
   that are grouped together to perform a certain
   task. There are two types of procedures:
   Subroutines: perform a single task, no
     return.
   Functions: perform a task and then return a
     value
Understanding VBA Terminology
− Module:   Procedures live in modules. A
  module consists of one or more procedures
− Variable: is nothing more than a name
  applied to represent a data value. Variable is
  used to hold values such as customer
  names,     dates,   and    numeric     values
  manipulated by the VBA code.
The Visual Basic Editor
 Visual Basic code is stored in database, but it
  need a different tool to view and edit it, called
  the Visual Basic editor.
 Open the Visual Basic editor:
    In the Access ribbon, choose Database
      Tools➝ Macro ➝ Visual Basic
The Visual Basic Editor
 The Visual Basic editor window is divided into
  three main regions.
 − Project window: shows all the modules in
   your database.
 − Properties window: which shows settings for
   the currently selected item in the Project
   window.
 − Document window: Edit code region.
Adding a New Module
 In the Visual Basic editor’s menu, choose Insert
  ➝ Module.
Adding a New Module
 When add a new module, the Visual Basic
  editor automatically opens a code window that
  shows the contents of that module.
 Initially, a brand-new module has just one line
  of code:
               Option Compare Database
 − This line is an instruction that tells Visual
    Basic how to handle operations that compare
    pieces of text.
Adding a New Module
 Before write code you should add one more
  instruction to the top of code file:
                  Option Explicit
 This instruction tells Visual Basic to use stricter
  error checking, which catches common typos
  when using variables.
Simplest Possible Code Routine
 Every module are one or more subroutines. A
  subroutine is a named unit of code that
  performs a distinct task.
 Subroutines start with the word Sub followed
  by the name of the subroutine and end with the
  statement End Sub
 Example:
   Sub MyCodeRoutine()
       MsgBox "Witness the power of my code."
   End Sub
Module types
 Access stores code in two places:
 − Class modules: attached to the form or
   report, it executes when the form or report is
   opened, the class module does not appear in
   the modules section.
 − Standard modules: Code can also be stored
   in modules section. Standard modules is
   accessible to all objects in your database.
Responding to a Form Event
 Open a form in Design mode.
 Turn off Control wizard button.
 Add a new button.
 In the  Property Sheet, choose the Event
  tab, and then select the button’s On Click
     event
 Click the ellipsis (…) in the On Click Event box
 Select Code Builder and click OK
008.module
008.module
008.module
008.module
008.module
008.module
008.module
008.module
008.module
008.module
008.module
008.module
008.module
008.module
008.module
008.module
008.module
008.module
008.module
008.module

More Related Content

ODP
Why Use MVC?
PDF
Just a View: An Introduction To Model-View-Controller Pattern
PPT
MVC Architecture
PPT
MVC(Model View Controller),Web,Enterprise,Mobile
PPTX
Mvc pattern and implementation in java fair
PPTX
Model view controller (mvc)
DOCX
Bm0025 visual basic
PPT
Why MVC?
Why Use MVC?
Just a View: An Introduction To Model-View-Controller Pattern
MVC Architecture
MVC(Model View Controller),Web,Enterprise,Mobile
Mvc pattern and implementation in java fair
Model view controller (mvc)
Bm0025 visual basic
Why MVC?

What's hot (20)

PDF
Principles of MVC for Rails Developers
PDF
MVC Architecture
PDF
MVC architecture
PDF
MVVM in iOS presentation
PPTX
ASP.NET MVC.
 
PPTX
Model view controller (mvc)
PPTX
MVC Framework
PDF
Model View Controller (MVC)
PPTX
Promostat original
PPTX
Introduction to mvc architecture
PPT
Ppt of Basic MVC Structure
PPT
MVC
ODP
What is MVC?
PPTX
Model View Controller(MVC)
PPT
6) debugging and testing
PPTX
MVC architecture by Mohd.Awais on 18th Aug, 2017
PPT
MVC ppt presentation
PPTX
An introduction to vba and macros
PPTX
Coded ui - lesson 3 - case study - calculator
Principles of MVC for Rails Developers
MVC Architecture
MVC architecture
MVVM in iOS presentation
ASP.NET MVC.
 
Model view controller (mvc)
MVC Framework
Model View Controller (MVC)
Promostat original
Introduction to mvc architecture
Ppt of Basic MVC Structure
MVC
What is MVC?
Model View Controller(MVC)
6) debugging and testing
MVC architecture by Mohd.Awais on 18th Aug, 2017
MVC ppt presentation
An introduction to vba and macros
Coded ui - lesson 3 - case study - calculator
Ad

Similar to 008.module (20)

PPTX
2-Vb.net Basic Concepts and structure of .net code.pptx
DOCX
Generic Repository Pattern in MVC3 Application with Entity Framework
PDF
Building richwebapplicationsusingasp
DOCX
LearningMVCWithLINQToSQL
PPT
AVB201.1 MS Access VBA Module 1
PPTX
Model View Presenter (MVP) In Aspnet
PPTX
Vb6.0 intro
PPTX
Ch07 cmpt110
PPTX
Login Project with introduction .pptx
PPT
Visual basics
DOCX
ASP.NET MVC3 RAD
PDF
.NET Portfolio
PPTX
Using general sub procedures
PDF
VBA Tips
DOCX
Learning MVC Part 3 Creating MVC Application with EntityFramework
PDF
DOCX
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
PDF
IBM Cognos 10 Framework Manager Metadata Modeling: Tips and Tricks
PPTX
Introduction to visual basic 6 (1)
PDF
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
2-Vb.net Basic Concepts and structure of .net code.pptx
Generic Repository Pattern in MVC3 Application with Entity Framework
Building richwebapplicationsusingasp
LearningMVCWithLINQToSQL
AVB201.1 MS Access VBA Module 1
Model View Presenter (MVP) In Aspnet
Vb6.0 intro
Ch07 cmpt110
Login Project with introduction .pptx
Visual basics
ASP.NET MVC3 RAD
.NET Portfolio
Using general sub procedures
VBA Tips
Learning MVC Part 3 Creating MVC Application with EntityFramework
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
IBM Cognos 10 Framework Manager Metadata Modeling: Tips and Tricks
Introduction to visual basic 6 (1)
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
Ad

More from Học Huỳnh Bá (20)

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

008.module

  • 1. Automating Tasks with Visual Basic
  • 2. Introduction  When can’t find a readymade macro action that does the job you want, you can use Visual Basic code.  Example: − Modify a whole batch of records at once. − Perform complex calculations. − Interact with other programs on computer. − Write even more complicated validation routines that lock out bad data.
  • 3. Understanding VBA Terminology  Some basic VBA terminology: − Statement: A word or combination of words that constitutes an instruction to be performed by the VBA engine. − Procedure: A collection of VBA statements that are grouped together to perform a certain task. There are two types of procedures:  Subroutines: perform a single task, no return.  Functions: perform a task and then return a value
  • 4. Understanding VBA Terminology − Module: Procedures live in modules. A module consists of one or more procedures − Variable: is nothing more than a name applied to represent a data value. Variable is used to hold values such as customer names, dates, and numeric values manipulated by the VBA code.
  • 5. The Visual Basic Editor  Visual Basic code is stored in database, but it need a different tool to view and edit it, called the Visual Basic editor.  Open the Visual Basic editor:  In the Access ribbon, choose Database Tools➝ Macro ➝ Visual Basic
  • 6. The Visual Basic Editor  The Visual Basic editor window is divided into three main regions. − Project window: shows all the modules in your database. − Properties window: which shows settings for the currently selected item in the Project window. − Document window: Edit code region.
  • 7. Adding a New Module  In the Visual Basic editor’s menu, choose Insert ➝ Module.
  • 8. Adding a New Module  When add a new module, the Visual Basic editor automatically opens a code window that shows the contents of that module.  Initially, a brand-new module has just one line of code: Option Compare Database − This line is an instruction that tells Visual Basic how to handle operations that compare pieces of text.
  • 9. Adding a New Module  Before write code you should add one more instruction to the top of code file: Option Explicit  This instruction tells Visual Basic to use stricter error checking, which catches common typos when using variables.
  • 10. Simplest Possible Code Routine  Every module are one or more subroutines. A subroutine is a named unit of code that performs a distinct task.  Subroutines start with the word Sub followed by the name of the subroutine and end with the statement End Sub  Example: Sub MyCodeRoutine() MsgBox "Witness the power of my code." End Sub
  • 11. Module types  Access stores code in two places: − Class modules: attached to the form or report, it executes when the form or report is opened, the class module does not appear in the modules section. − Standard modules: Code can also be stored in modules section. Standard modules is accessible to all objects in your database.
  • 12. Responding to a Form Event  Open a form in Design mode.  Turn off Control wizard button.  Add a new button.  In the Property Sheet, choose the Event tab, and then select the button’s On Click event  Click the ellipsis (…) in the On Click Event box  Select Code Builder and click OK