SlideShare una empresa de Scribd logo
1 de 32
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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

MVC Architecture
MVC ArchitectureMVC Architecture
MVC Architecture
 
Principles of MVC for Rails Developers
Principles of MVC for Rails DevelopersPrinciples of MVC for Rails Developers
Principles of MVC for Rails Developers
 
MVC Architecture
MVC ArchitectureMVC Architecture
MVC Architecture
 
MVC architecture
MVC architectureMVC architecture
MVC architecture
 
MVVM in iOS presentation
MVVM in iOS presentationMVVM in iOS presentation
MVVM in iOS presentation
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.
 
Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
 
Model View Controller (MVC)
Model View Controller (MVC)Model View Controller (MVC)
Model View Controller (MVC)
 
Promostat original
Promostat originalPromostat original
Promostat original
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
 
Ppt of Basic MVC Structure
Ppt of Basic MVC StructurePpt of Basic MVC Structure
Ppt of Basic MVC Structure
 
MVC
MVCMVC
MVC
 
What is MVC?
What is MVC?What is MVC?
What is MVC?
 
Model View Controller(MVC)
Model View Controller(MVC)Model View Controller(MVC)
Model View Controller(MVC)
 
6) debugging and testing
6) debugging and testing6) debugging and testing
6) debugging and testing
 
MVC architecture by Mohd.Awais on 18th Aug, 2017
MVC architecture by Mohd.Awais on 18th Aug, 2017MVC architecture by Mohd.Awais on 18th Aug, 2017
MVC architecture by Mohd.Awais on 18th Aug, 2017
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
 
An introduction to vba and macros
An introduction to vba and macrosAn introduction to vba and macros
An introduction to vba and macros
 
Coded ui - lesson 3 - case study - calculator
Coded ui - lesson 3 - case study - calculatorCoded ui - lesson 3 - case study - calculator
Coded ui - lesson 3 - case study - calculator
 

Similar a 008.module

2-Vb.net Basic Concepts and structure of .net code.pptx
2-Vb.net Basic Concepts and structure of .net code.pptx2-Vb.net Basic Concepts and structure of .net code.pptx
2-Vb.net Basic Concepts and structure of .net code.pptxUsama182938
 
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
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLAkhil Mittal
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1guest38bf
 
Model View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In AspnetModel View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In Aspnetrainynovember12
 
Login Project with introduction .pptx
Login Project with introduction .pptxLogin Project with introduction .pptx
Login Project with introduction .pptxkulmiyealiabdille
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
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
 
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPMCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPAli Shah
 
IBM Cognos 10 Framework Manager Metadata Modeling: Tips and Tricks
IBM Cognos 10 Framework Manager Metadata Modeling: Tips and TricksIBM Cognos 10 Framework Manager Metadata Modeling: Tips and Tricks
IBM Cognos 10 Framework Manager Metadata Modeling: Tips and TricksSenturus
 
Introduction to visual basic 6 (1)
Introduction to visual basic 6 (1)Introduction to visual basic 6 (1)
Introduction to visual basic 6 (1)Mark Vincent Cantero
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010vchircu
 

Similar a 008.module (20)

2-Vb.net Basic Concepts and structure of .net code.pptx
2-Vb.net Basic Concepts and structure of .net code.pptx2-Vb.net Basic Concepts and structure of .net code.pptx
2-Vb.net Basic Concepts and structure of .net code.pptx
 
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
 
Building richwebapplicationsusingasp
Building richwebapplicationsusingaspBuilding richwebapplicationsusingasp
Building richwebapplicationsusingasp
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
 
Model View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In AspnetModel View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In Aspnet
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Ch07 cmpt110
Ch07 cmpt110Ch07 cmpt110
Ch07 cmpt110
 
Login Project with introduction .pptx
Login Project with introduction .pptxLogin Project with introduction .pptx
Login Project with introduction .pptx
 
Visual basics
Visual basicsVisual basics
Visual basics
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Using general sub procedures
Using general sub proceduresUsing general sub procedures
Using general sub procedures
 
VBA Tips
VBA TipsVBA Tips
VBA Tips
 
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
 
VBA
VBAVBA
VBA
 
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPMCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
 
IBM Cognos 10 Framework Manager Metadata Modeling: Tips and Tricks
IBM Cognos 10 Framework Manager Metadata Modeling: Tips and TricksIBM Cognos 10 Framework Manager Metadata Modeling: Tips and Tricks
IBM Cognos 10 Framework Manager Metadata Modeling: Tips and Tricks
 
Introduction to visual basic 6 (1)
Introduction to visual basic 6 (1)Introduction to visual basic 6 (1)
Introduction to visual basic 6 (1)
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 

Más de Học Huỳnh Bá

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ẤTHọc Huỳnh Bá
 
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ừ ...Học Huỳnh Bá
 
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 inHọc Huỳnh Bá
 
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...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á
 
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)鞋类常见词汇(英语、汉语、...Học Huỳnh Bá
 
Chinese email 高职高专院校英语能力测试a b级
Chinese email  高职高专院校英语能力测试a b级Chinese email  高职高专院校英语能力测试a b级
Chinese email 高职高专院校英语能力测试a b级Học Huỳnh Bá
 
English chinese business languages bec中级写作电子讲义
English   chinese business languages bec中级写作电子讲义English   chinese business languages bec中级写作电子讲义
English chinese business languages bec中级写作电子讲义Học Huỳnh Bá
 
Chinese english writing skill - 商务写作教程
Chinese english writing skill  - 商务写作教程Chinese english writing skill  - 商务写作教程
Chinese english writing skill - 商务写作教程Học Huỳnh Bá
 
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ẩuHọc Huỳnh Bá
 
祈福英语实验学校入学申请表 Clifford school application form
祈福英语实验学校入学申请表 Clifford school application form祈福英语实验学校入学申请表 Clifford school application form
祈福英语实验学校入学申请表 Clifford school application formHọc Huỳnh Bá
 
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À...Học Huỳnh Bá
 
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ườngHọc Huỳnh Bá
 
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 2003Học Huỳnh Bá
 
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 2003Học Huỳnh Bá
 
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òngHọc Huỳnh Bá
 
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)Học Huỳnh Bá
 
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ữ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á
 

Más de 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
 

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