SlideShare a Scribd company logo
AVB201 Visual Basic For Applications MS Access, Beginning Course P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.dhdursoassociates.com [email_address]
OUTLINE SESSION 1: Event driven Programming in Access (3 hours). SESSION 2: VBA Language Constructs and Programming Techniques (3 hours). AVB202: Working Programmatically with Data (3 hours).
Product Sales Sample Database
Session 1: Event Driven Programming in Access Why VBA ? Using events and event procedures. Using VBA Editor. Event types in Access. Differentiating between functions and sub procedures. Organizing VBA code into modules. Using Variables, Scope, and Data types. Exploring and using built-in functions.

Recommended for you

Excel vba
Excel vbaExcel vba
Excel vba

This document provides an introduction to Visual Basic for Applications (VBA) in Excel. It explains how to add the Developer toolbar to access VBA features in Excel. It then describes the Excel VBA development environment and how to write simple macros to automate tasks like formatting cells. Examples are provided of recording macros to demonstrate how VBA code is generated. The document emphasizes that recorded macros contain more code than is needed and that writing your own VBA code results in more efficient macros.

Vba part 1
Vba part 1Vba part 1
Vba part 1

VBA can be used in Excel to automate tasks, create custom functions and commands, and develop complete applications. Some advantages of VBA include allowing tasks to be performed faster, consistently, and without errors by the user. However, VBA also requires knowledge of programming and debugging issues may arise. The document then covers various aspects of working with VBA like the Excel object model, declaring variables, using operators, arrays, ranges and more.

Visual Basics for Application
Visual Basics for Application Visual Basics for Application
Visual Basics for Application

This document discusses variables, data types, and string functions in Visual Basic for Applications (VBA) with Excel. It defines different variable types like integer, string, date, and variants. Mathematical and string operators that can be used with variables are also presented. The document explains declaring and initializing variables, variable scope, and using constants to give names to values. Common string functions like Str, Val, Trim, Left, Right and Mid are also summarized.

1.1 Why VBA ? Greatly extends the functionality of Macros. Allows customized interactions with users. Enables complex operations on records. Enables complete control over the Access Object Model Capable of making reports and forms that can make decisions based on user choices, database data, and user supplied values. Offers improved error handling capabilities. Programming is FUN !!
1.2 Events and Event Procedures Event is when something happens to any object in your application. Ex: User clicks a button (object) on a form (also an object). Event Procedure is a piece of VBA code that is associated with this object and this event. Since event code is programmed the event can trigger any number of actions. Ex: deleting a record and closing the form. In such event driven programming model, the user is in control of when and what should happen next in the application.
1.3 Using VBA Editor VBA editor is the place where you write your VBA code. Enter via code builder, CTRL G, etc. VBA editor keeps your code organized into modules, functions, procedures, and/or classes (more on module types later). You can write, document, test, compile, and debug your code with supplied tools >>  explore  VBA menus. We will use the VBA editor for the rest of this course.
1.3 Using VBA Editor Demonstration:  Make “Add New” command button on a Products form.

Recommended for you

E learning excel vba programming lesson 4
E learning excel vba programming  lesson 4E learning excel vba programming  lesson 4
E learning excel vba programming lesson 4

Declaring Variables , Data Types and Examples are discussed in this session. For Complete powerpoint and related Free online class visit www.ameetz.com

Online Advance Excel & VBA Training in India
 Online Advance Excel & VBA Training in India Online Advance Excel & VBA Training in India
Online Advance Excel & VBA Training in India

In today’s era, Investment banking courses are considered as the best path to make bright future. These courses includes financial modeling training, basic & advance excel training, excel dashboard 2010 course, financial modeling & company valuation training, relative valuation etc. Investment banking Institute (IBI) in Delhi provides such types of training of best level in weekend classes. IB Institute provides Online & corporate financial modeling & company valuation training in Delhi, India.

excel dashboard 2010 coursesonline financial modeling trainingvba training
Cordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptCordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to Javascript

This document provides an introduction to JavaScript, including: - JavaScript is a lightweight, interpreted programming language commonly used in web pages. - Advantages of JavaScript include less server interaction, immediate feedback, and richer interfaces. - Disadvantages include inability to read/write files for security and lack of multithreading. - JavaScript syntax can be included in HTML using <script> tags and ignores spaces/newlines. - Basic data types are strings, numbers, and Booleans, and variables are declared with var. - Common operators include arithmetic, comparison, logical, and assignment operators. - Control structures include if/else statements, switch statements, for/while loops. - Functions are reusable blocks

apache cordovacordovaapps
..cont Exercise: Add “Delete” button to Products form and check the procedure. Explore changing the code and see how VBA automatically notifies you of certain errors. Run procedure by clicking the “Delete” command button.
1.4 Types of Events in Access Events in Access can be categorized into several groups: Windows (Form, Report): opening, closing, resizing. Data: making current, deleting, updating. Focus: activating, entering, exiting. Keyboard: pressing or releasing a key. Mouse: clicking a mouse button. Print: formatting, printing. Error and timing: when error occurs in code or some time passes.
Commonly Used Events Events are normally associated with a form, report, or some control on a form. Some common form events are: On Open, On Load, Before Update, On Unload, On Current On Delete Before Delete.
Common Control Events On Click Before Update After Update On Double Click.

Recommended for you

2016 Excel/VBA Notes
2016 Excel/VBA Notes2016 Excel/VBA Notes
2016 Excel/VBA Notes

On May 20, Visual Basic is 25 years old! Congrats to VB! Yet Microsoft is not to open source Visual Basic. VBA has become a precious species. Here I am to share some notes on Excel/VBA.

Cis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programmingCis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programming

This lab aims to develop students knowledge and skills needed to create a simple programming code. It covers the process of developing computer programs starting from a simple analysis of the problem, identifying outputs, inputs, and design process/algorithm, convert algorithm to code, testing, and documentation. The student will be introduced to the Java program structure, numerical variable and high-level introduction to data types. The lab does not go into depth explaining the data types and memory storage. These will be discussed in the upcoming labs. Also, the student will be introduced to the REPL cloud environment that will be used to create a simple application.

hctcis 1403fundamentals of programming
Cis 1403 lab5_loops
Cis 1403 lab5_loopsCis 1403 lab5_loops
Cis 1403 lab5_loops

This lab aims to develop your knowledge and skills to apply various iteration/loop technique to solve a programming problem. The lab will cover the structure of for, while and do-while loops, provide examples on when to apply each. Exceptions handling and reading from an external text file are also covered with examples.

cis 1403java programmingfundamentals of programming in java
Common Report Events On Open On Activate On Close On No Data.
Event Flow NOTE: A single user action can also trigger several events that then run in succession. For example when the user opens a form all of the following events occur: Open >> Load >> Resize >> Activate >> Current
1.5 Differentiating between Functions and Sub Procedures. Functions return a value to the calling code, usually providing the result of the function’s operation. Sub Procedures execute the code in the procedure but do not return any values. Both, functions and procedures, can accept multiple input values from the calling program that can be used inside their respective operations.
..cont Function Syntax: Function FunctionName(passed arguments) As “Data Type of Return” ..some code.. FunctionName = “Return Value” End Function

Recommended for you

Intro to Excel VBA Programming
Intro to Excel VBA ProgrammingIntro to Excel VBA Programming
Intro to Excel VBA Programming

This document provides an introduction and agenda for learning introductory VBA programming. It covers variables including types, declaration, and assignment. It also discusses functions/subroutines, specifically parameters and returning values. Finally, it discusses loops, including while and for loops. The goal is to teach the basic building blocks of programming like variables, functions, and loops using the VBA language.

microsoft excelprogramming languageivey
Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...
Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...
Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...

Download for higher quality. I find out what the changes are to the smells of Shotgun Surgery and Divergent Change in the 2019 edition of Refactoring and realise that some bits have been removed that I found valuable. E.g. a section has been removed which IMHO highlights and pithily expresses the duality of the two smells, plus naturally links up with how they complement each other in the Single Responsibility Principle, in which the smells also line up with coupling and cohesion.

bad smells in codecohesion srpcoupling
Introduction to programming by MUFIX Commnity
Introduction to programming by MUFIX CommnityIntroduction to programming by MUFIX Commnity
Introduction to programming by MUFIX Commnity

Programming involves breaking problems down into simple steps that a computer can understand through instructions. It requires defining problems clearly and solving them by describing actions, modeling data, and refining solutions iteratively. Effective programming tools include action lists, flow charts, and data modeling to design solutions before writing code. Statements, blocks, variables, loops, functions, conditionals, and input/output allow computers to repeat tasks, store and manipulate data, and make decisions.

introducrtionmufix communityc
..cont Sub Procedure Syntax: Sub SubName(passed arguments) ..some code.. End Sub
1.6 Organizing VBA Code into Modules All event procedures and any other VBA code are grouped and placed into “Modules”. MS Access has 4 types of modules: Standard, Form, Report, and Class. Each form and report has its own form or report module. All event procedures associated with a particular form or report should reside in their respective module. Standard module holds any other common or non form/report specific code. Class modules support object oriented programming approach (OOP) to development.
..cont Exercise:  Access any of the module types. In all cases you work with the same VBA editor.
..cont This is the place where we start writing some of our own code. Interactive  Exercise : Create new standard module. Type in the following code: Function Area (Height As Double, Width As Double) As Double Area = Width * Height End Function Optionally compile code (under Debug menu). Run code in Immediate window: ?Area(3,4)

Recommended for you

MACROS excel
MACROS excelMACROS excel
MACROS excel

The document discusses macros in Excel. It explains that macros allow users to record a series of steps like formatting cells or entering text and replay those steps without repeating the actions. It describes how to record a basic macro by selecting cells, entering text, and formatting font and interior before playing back the macro on a new range of cells. The summary code generated by the recording is also shown.

How to apply a formula and macro in excel......by irfan afzal
How to apply a formula and macro in excel......by irfan afzalHow to apply a formula and macro in excel......by irfan afzal
How to apply a formula and macro in excel......by irfan afzal

This document provides an introduction to key concepts in Excel including: - Entering formulas using the equals sign to indicate a cell contains a formula. Formulas use function syntax of name, parentheses, and arguments separated by commas. - Transferring data between sheets by copying or moving selected data using keyboard shortcuts and pasting into another sheet that can be in the same or different workbook. - Macros which automate repetitive tasks by recording mouse actions to create a series of functions in a programming language that can be run with a single command. The macro recorder allows creating macros by recording actions.

Code Smells and Its type (With Example)
Code Smells and Its type (With Example)Code Smells and Its type (With Example)
Code Smells and Its type (With Example)

This document discusses code smells, which are indications of poor coding practices that can cause problems later. It defines code smells and code refactoring. Several types of code smells are described in detail, including duplicate code, long methods, large classes, divergent change, shotgun surgery, feature envy, and data clumps. Advanced techniques for dynamically detecting feature envy are also discussed. The document provides examples and explanations for how to identify and refactor code to address these smells.

code refactoringsoftware development
..cont And now try the following procedure: Sub MyLoop() Dim loopcount As Integer, i As Integer loopcount = 3 For i = 1 To loopcount Debug.Print &quot;Loop &quot;, i Next i Beep End Sub More about “For” statement in Session 2.
1.7 Variables, Scope, and Data Types Variables are containers that hold your data in programs. Each variable should have a type. VBA supports a wide range of data types that are not identical to data types declared on fields in tables. Knowing both groups and how to map them is essential for good programming. If you forget to assign type to a variable in VBA, then the variable is treated as a “Variant”. Variants assume data type when data is loaded in to the variable. NOTE:   !! Avoid using Variants”. They slow the execution and make for poor documentation.
Some often used data types in VBA Boolean (True or False) Currency (formatted number $56.67) Double, Single (51.145678) Integer (321) Date (#8/28/04#) String (“Any word or sentence”) Q: What are their equivalents in database tables?
Scope of Variables (and Procedures) Scope determines where can variable be used. This depends on the place where and also how it was declared. Variables declared inside functions or subs must be declared with a Dim statement. They are always local to that sub or function..

Recommended for you

Abstract
AbstractAbstract
Abstract

This document discusses polymorphism and how it allows objects to be treated as their base type. With polymorphism, code can be written that manipulates generic objects without knowing their specific type. When a message is sent to an object, late binding determines at runtime which implementation of a method is executed based on the object's actual type. This allows code to work correctly even when new subclasses are added, improving extensibility and reducing maintenance costs. Abstract base classes and interfaces provide a way to define common interfaces for subclasses without requiring implementation in the base class.

Roma 2014
Roma 2014Roma 2014
Roma 2014

Viatge fi curs 2014 a Itàlia Institut Arnau Cadell

itàliaarnau cadellviatge
Managing Your Career In Tough Times 102308
Managing Your Career In Tough Times 102308Managing Your Career In Tough Times 102308
Managing Your Career In Tough Times 102308

The document provides tips for managing your career in tough economic times. It recommends 1) being visible and valuable to your employer and clients, 2) investing in your own education, 3) keeping your resume updated, 4) maintaining a cash reserve, and 5) building your network before you need it. The document stresses taking control of your own career and treating your job like running a self-employed business.

…cont Variables declared outside any function or sub are always global to that module. Whether they are also available to other modules, depends on what you precede their declarations with: “ Private Area As Double” would be same as “Dim Area As Double”. “ Public Area As Double” on the other hand is global to the application. NOTE: !!You can not use Public declaration inside function or sub. Use Dim ONLY.
..cont Functions and Procedures also have a scope. Preceding function or procedure declaration with a word “Public” or “Private” makes that function or sub available “in the module where declared only” OR they can be called (used) from any place in the application. Ex: Procedure in one module can call Public functions declared in any other module.  Public and Private declarations are useful to avoid confusion with keeping track of multiple names used for variables, functions, and procedures. Similar operations on two different forms can use procedures with same name as long as they are both declared as private in their respective modules.
..cont Exercise: Modify the MyLoop procedure to accept the number of loops. Call the new one  MyAreaLoop Call the Area function procedure from the MyAreaLoop procedure and pass it a length 0f 10 and width of I. (You will have to set up a variable of type double for area.) Run the MyAreaLoop procedure.
..cont Exercise: Sub MyAreaLoop(numloops As Integer) Dim loopnum As Double, i As Integer For i = 1 To numloops loopnum = i Debug.Print &quot;Area &quot;, i, Area(10, loopnum) Next i Beep End Sub

Recommended for you

Ese Psg Powerpoint Show 102807
Ese Psg Powerpoint Show 102807Ese Psg Powerpoint Show 102807
Ese Psg Powerpoint Show 102807

Eastern Sales and Engineering (ESE) is an experienced fueling equipment contractor that has been family-owned for over 50 years. ESE provides installation, maintenance, and repair services for point of sale systems, fuel dispensers, and automatic tank gauging equipment. Their technicians are trained on Dresser Wayne, Verifone, Veeder Root, Incon, and Gilbarco equipment and aim to minimize downtime for customers. ESE offers both time and material and comprehensive maintenance contract plans.

Link Journalism: Curation to increase trust, relevance, brevity and pageviews
Link Journalism: Curation to increase trust, relevance, brevity and pageviewsLink Journalism: Curation to increase trust, relevance, brevity and pageviews
Link Journalism: Curation to increase trust, relevance, brevity and pageviews

Vannevar Bush in 1945 advocated for a new profession of curating and establishing useful trails through the vast amount of information being created and archived. The document provides guidance on best practices for linking in journalism, including only linking to accurate, relevant, and specific sources, and avoiding potentially offensive or illegal material. It discusses linking nouns and verbs as departure points from text, using inline, sidebar, and bottom links, and crafting clear and descriptive link text and labels.

..cont Mini-Quiz: If you change the Area function to private does myarealoop still work? Why? How could you use global variables? Should you?
1.8 Built-in Functions and Procedures Beside custom made functions and procedures there are some that are built-in and part of the Access VBA language. We will see several examples in the following Sessions. “ Beep” is an example of built-in procedure and performs a single operation: It makes computer beep. Once. Built-in functions can be used anywhere in your program. Knowing what is available is essential for efficient programming so we don’t go and try to reinvent the wheel.
Some Common built-in Functions Today = Date() returns today’s date. UCase(String) converts all letters in string to upper case. Round(3.89) rounds a value in parenthesis to nearest integer (4 here). Len(String) returns number of characters in a string. NOTE:  There are close to 100 built in functions available for almost any area of data manipulation. Check some reference book for complete list or consult an Online Help in Access. We will introduce and use several in the hours ahead.
..cont Built-in functions are grouped into several categories: Conversion (converts one data type to another. UCase, LCase, etc..) Date/Time Financial Mathematical String Manipulation (extract parts of string, truncate, etc..) Programming (check for missing values, determine data types etc..) Domain (work on several values at once and perform statistical operations such as average, finding maximum / minimum value etc..)

Recommended for you

My Logo Portfolio
My Logo PortfolioMy Logo Portfolio
My Logo Portfolio
Show Your Work: Cheap & Easy Tools for Presenting Data
Show Your Work: Cheap & Easy Tools for Presenting DataShow Your Work: Cheap & Easy Tools for Presenting Data
Show Your Work: Cheap & Easy Tools for Presenting Data

This document provides recommendations for cheap and easy tools for presenting data, including using H.264 video codec at 1280x720 resolution and 3000-5000 kbps bitrate for optimized download of videos. It also recommends audio codec of AAC at 128 kbps stereo and lists websites like Scribd, DocumentCloud, and Google Docs that allow uploading documents to share data on websites.

Muziekdigitaal Taggerfm Pitch 091027
Muziekdigitaal Taggerfm Pitch 091027Muziekdigitaal Taggerfm Pitch 091027
Muziekdigitaal Taggerfm Pitch 091027
..cont Try a couple from the immediate window:
AVB201 – Introduction to VBA Session 1 END

More Related Content

What's hot

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
Vijay Perepa
 
Vba
Vba Vba
Introduction to Excel VBA/Macros
Introduction to Excel VBA/MacrosIntroduction to Excel VBA/Macros
Introduction to Excel VBA/Macros
arttan2001
 
Excel vba
Excel vbaExcel vba
Excel vba
Almeda Asuncion
 
Vba part 1
Vba part 1Vba part 1
Vba part 1
Morteza Noshad
 
Visual Basics for Application
Visual Basics for Application Visual Basics for Application
Visual Basics for Application
Raghu nath
 
E learning excel vba programming lesson 4
E learning excel vba programming  lesson 4E learning excel vba programming  lesson 4
E learning excel vba programming lesson 4
Vijay Perepa
 
Online Advance Excel & VBA Training in India
 Online Advance Excel & VBA Training in India Online Advance Excel & VBA Training in India
Online Advance Excel & VBA Training in India
ibinstitute0
 
Cordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptCordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to Javascript
Binu Paul
 
2016 Excel/VBA Notes
2016 Excel/VBA Notes2016 Excel/VBA Notes
2016 Excel/VBA Notes
Yang Ye
 
Cis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programmingCis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programming
Hamad Odhabi
 
Cis 1403 lab5_loops
Cis 1403 lab5_loopsCis 1403 lab5_loops
Cis 1403 lab5_loops
Hamad Odhabi
 
Intro to Excel VBA Programming
Intro to Excel VBA ProgrammingIntro to Excel VBA Programming
Intro to Excel VBA Programming
iveytechnologyclub
 
Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...
Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...
Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...
Philip Schwarz
 
Introduction to programming by MUFIX Commnity
Introduction to programming by MUFIX CommnityIntroduction to programming by MUFIX Commnity
Introduction to programming by MUFIX Commnity
mazenet
 
MACROS excel
MACROS excelMACROS excel
MACROS excel
Zenobia Sukhia
 
How to apply a formula and macro in excel......by irfan afzal
How to apply a formula and macro in excel......by irfan afzalHow to apply a formula and macro in excel......by irfan afzal
How to apply a formula and macro in excel......by irfan afzal
1995786
 
Code Smells and Its type (With Example)
Code Smells and Its type (With Example)Code Smells and Its type (With Example)
Code Smells and Its type (With Example)
Anshul Vinayak
 
Abstract
AbstractAbstract
Abstract
snehajyothi
 

What's hot (19)

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
 
Vba
Vba Vba
Vba
 
Introduction to Excel VBA/Macros
Introduction to Excel VBA/MacrosIntroduction to Excel VBA/Macros
Introduction to Excel VBA/Macros
 
Excel vba
Excel vbaExcel vba
Excel vba
 
Vba part 1
Vba part 1Vba part 1
Vba part 1
 
Visual Basics for Application
Visual Basics for Application Visual Basics for Application
Visual Basics for Application
 
E learning excel vba programming lesson 4
E learning excel vba programming  lesson 4E learning excel vba programming  lesson 4
E learning excel vba programming lesson 4
 
Online Advance Excel & VBA Training in India
 Online Advance Excel & VBA Training in India Online Advance Excel & VBA Training in India
Online Advance Excel & VBA Training in India
 
Cordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptCordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to Javascript
 
2016 Excel/VBA Notes
2016 Excel/VBA Notes2016 Excel/VBA Notes
2016 Excel/VBA Notes
 
Cis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programmingCis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programming
 
Cis 1403 lab5_loops
Cis 1403 lab5_loopsCis 1403 lab5_loops
Cis 1403 lab5_loops
 
Intro to Excel VBA Programming
Intro to Excel VBA ProgrammingIntro to Excel VBA Programming
Intro to Excel VBA Programming
 
Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...
Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...
Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...
 
Introduction to programming by MUFIX Commnity
Introduction to programming by MUFIX CommnityIntroduction to programming by MUFIX Commnity
Introduction to programming by MUFIX Commnity
 
MACROS excel
MACROS excelMACROS excel
MACROS excel
 
How to apply a formula and macro in excel......by irfan afzal
How to apply a formula and macro in excel......by irfan afzalHow to apply a formula and macro in excel......by irfan afzal
How to apply a formula and macro in excel......by irfan afzal
 
Code Smells and Its type (With Example)
Code Smells and Its type (With Example)Code Smells and Its type (With Example)
Code Smells and Its type (With Example)
 
Abstract
AbstractAbstract
Abstract
 

Viewers also liked

Roma 2014
Roma 2014Roma 2014
Managing Your Career In Tough Times 102308
Managing Your Career In Tough Times 102308Managing Your Career In Tough Times 102308
Managing Your Career In Tough Times 102308
Joellyn Schwerdlin
 
Ese Psg Powerpoint Show 102807
Ese Psg Powerpoint Show 102807Ese Psg Powerpoint Show 102807
Ese Psg Powerpoint Show 102807
podczaski
 
Link Journalism: Curation to increase trust, relevance, brevity and pageviews
Link Journalism: Curation to increase trust, relevance, brevity and pageviewsLink Journalism: Curation to increase trust, relevance, brevity and pageviews
Link Journalism: Curation to increase trust, relevance, brevity and pageviews
Ryan Thornburg
 
My Logo Portfolio
My Logo PortfolioMy Logo Portfolio
My Logo Portfolio
beth7865
 
Show Your Work: Cheap & Easy Tools for Presenting Data
Show Your Work: Cheap & Easy Tools for Presenting DataShow Your Work: Cheap & Easy Tools for Presenting Data
Show Your Work: Cheap & Easy Tools for Presenting Data
Ryan Thornburg
 
Muziekdigitaal Taggerfm Pitch 091027
Muziekdigitaal Taggerfm Pitch 091027Muziekdigitaal Taggerfm Pitch 091027
Muziekdigitaal Taggerfm Pitch 091027
Tim Rootsaert
 
Course Catalog
Course CatalogCourse Catalog
Course Catalog
Dan D'Urso
 
青年創業及圓夢網 創業稅務大小事【創業懶人包 】
青年創業及圓夢網 創業稅務大小事【創業懶人包 】青年創業及圓夢網 創業稅務大小事【創業懶人包 】
青年創業及圓夢網 創業稅務大小事【創業懶人包 】
RICK Lin
 
Dutch Overheid20
Dutch   Overheid20Dutch   Overheid20
Dutch Overheid20
BZK
 
My Print Portfolio
My Print PortfolioMy Print Portfolio
My Print Portfolio
beth7865
 
SQL212.1 Introduction to SQL using Oracle Module 1
SQL212.1 Introduction to SQL using Oracle Module 1SQL212.1 Introduction to SQL using Oracle Module 1
SQL212.1 Introduction to SQL using Oracle Module 1
Dan D'Urso
 
RENÉ DESCARTES : PERFIL
RENÉ DESCARTES : PERFIL RENÉ DESCARTES : PERFIL
RENÉ DESCARTES : PERFIL
JAVIER ALSINA GONZALEZ
 
El nazisme viscut des del bàndol alemany (clotet, conangla)
El nazisme viscut des del bàndol alemany (clotet, conangla)El nazisme viscut des del bàndol alemany (clotet, conangla)
El nazisme viscut des del bàndol alemany (clotet, conangla)
JAVIER ALSINA GONZALEZ
 
Widget SOA
Widget SOAWidget SOA
Widget SOA
Stephen Anthony
 
Profit Hunters
Profit HuntersProfit Hunters
Profit Hunters
Cory Rhodes
 
Taggerfm Artist 091116
Taggerfm Artist 091116Taggerfm Artist 091116
Taggerfm Artist 091116
Tim Rootsaert
 
IntelliStick
IntelliStickIntelliStick
IntelliStick
Rhonda Williams
 
成衣服飾產業發展趨勢-創業懶人包-青年創業及圓夢網
成衣服飾產業發展趨勢-創業懶人包-青年創業及圓夢網成衣服飾產業發展趨勢-創業懶人包-青年創業及圓夢網
成衣服飾產業發展趨勢-創業懶人包-青年創業及圓夢網
RICK Lin
 

Viewers also liked (20)

Roma 2014
Roma 2014Roma 2014
Roma 2014
 
Managing Your Career In Tough Times 102308
Managing Your Career In Tough Times 102308Managing Your Career In Tough Times 102308
Managing Your Career In Tough Times 102308
 
Ese Psg Powerpoint Show 102807
Ese Psg Powerpoint Show 102807Ese Psg Powerpoint Show 102807
Ese Psg Powerpoint Show 102807
 
Filoarnaucadell
Filoarnaucadell Filoarnaucadell
Filoarnaucadell
 
Link Journalism: Curation to increase trust, relevance, brevity and pageviews
Link Journalism: Curation to increase trust, relevance, brevity and pageviewsLink Journalism: Curation to increase trust, relevance, brevity and pageviews
Link Journalism: Curation to increase trust, relevance, brevity and pageviews
 
My Logo Portfolio
My Logo PortfolioMy Logo Portfolio
My Logo Portfolio
 
Show Your Work: Cheap & Easy Tools for Presenting Data
Show Your Work: Cheap & Easy Tools for Presenting DataShow Your Work: Cheap & Easy Tools for Presenting Data
Show Your Work: Cheap & Easy Tools for Presenting Data
 
Muziekdigitaal Taggerfm Pitch 091027
Muziekdigitaal Taggerfm Pitch 091027Muziekdigitaal Taggerfm Pitch 091027
Muziekdigitaal Taggerfm Pitch 091027
 
Course Catalog
Course CatalogCourse Catalog
Course Catalog
 
青年創業及圓夢網 創業稅務大小事【創業懶人包 】
青年創業及圓夢網 創業稅務大小事【創業懶人包 】青年創業及圓夢網 創業稅務大小事【創業懶人包 】
青年創業及圓夢網 創業稅務大小事【創業懶人包 】
 
Dutch Overheid20
Dutch   Overheid20Dutch   Overheid20
Dutch Overheid20
 
My Print Portfolio
My Print PortfolioMy Print Portfolio
My Print Portfolio
 
SQL212.1 Introduction to SQL using Oracle Module 1
SQL212.1 Introduction to SQL using Oracle Module 1SQL212.1 Introduction to SQL using Oracle Module 1
SQL212.1 Introduction to SQL using Oracle Module 1
 
RENÉ DESCARTES : PERFIL
RENÉ DESCARTES : PERFIL RENÉ DESCARTES : PERFIL
RENÉ DESCARTES : PERFIL
 
El nazisme viscut des del bàndol alemany (clotet, conangla)
El nazisme viscut des del bàndol alemany (clotet, conangla)El nazisme viscut des del bàndol alemany (clotet, conangla)
El nazisme viscut des del bàndol alemany (clotet, conangla)
 
Widget SOA
Widget SOAWidget SOA
Widget SOA
 
Profit Hunters
Profit HuntersProfit Hunters
Profit Hunters
 
Taggerfm Artist 091116
Taggerfm Artist 091116Taggerfm Artist 091116
Taggerfm Artist 091116
 
IntelliStick
IntelliStickIntelliStick
IntelliStick
 
成衣服飾產業發展趨勢-創業懶人包-青年創業及圓夢網
成衣服飾產業發展趨勢-創業懶人包-青年創業及圓夢網成衣服飾產業發展趨勢-創業懶人包-青年創業及圓夢網
成衣服飾產業發展趨勢-創業懶人包-青年創業及圓夢網
 

Similar to AVB201.1 MS Access VBA Module 1

AVB201.1 Microsoft Access VBA Module 1
AVB201.1 Microsoft Access VBA Module 1AVB201.1 Microsoft Access VBA Module 1
AVB201.1 Microsoft Access VBA Module 1
Dan D'Urso
 
Introduction to Visual Basic
Introduction to Visual Basic Introduction to Visual Basic
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
JOSEPHINEA6
 
S D D Program Development Tools
S D D  Program  Development  ToolsS D D  Program  Development  Tools
S D D Program Development Tools
gavhays
 
Functional programming in TypeScript
Functional programming in TypeScriptFunctional programming in TypeScript
Functional programming in TypeScript
binDebug WorkSpace
 
Using general sub procedures
Using general sub proceduresUsing general sub procedures
Using general sub procedures
Danica Denice Epino
 
Introduction to Visual Basic 6.0
Introduction to Visual Basic 6.0Introduction to Visual Basic 6.0
Introduction to Visual Basic 6.0
DivyaR219113
 
Ms vb
Ms vbMs vb
Ms vb
sirjade4
 
PRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdfPRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdf
jaymaraltamera
 
Lecture11 abap on line
Lecture11 abap on lineLecture11 abap on line
Lecture11 abap on line
Milind Patil
 
Vb introduction.
Vb introduction.Vb introduction.
Vb introduction.
sagaroceanic11
 
Mastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsMastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_arguments
Ruth Marvin
 
Mvp pattern
Mvp patternMvp pattern
Mvp pattern
Khuong Vo
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
Aarti P
 
Example Of Import Java
Example Of Import JavaExample Of Import Java
Example Of Import Java
Melody Rios
 
Oopp Lab Work
Oopp Lab WorkOopp Lab Work
Oopp Lab Work
Heather Dionne
 
VBA
VBAVBA
Electrical shop management system project report.pdf
Electrical shop management system project report.pdfElectrical shop management system project report.pdf
Electrical shop management system project report.pdf
Kamal Acharya
 
Book management system
Book management systemBook management system
Book management system
SHARDA SHARAN
 
Medicine For World
Medicine For WorldMedicine For World
Medicine For World
Saifur Rahman
 

Similar to AVB201.1 MS Access VBA Module 1 (20)

AVB201.1 Microsoft Access VBA Module 1
AVB201.1 Microsoft Access VBA Module 1AVB201.1 Microsoft Access VBA Module 1
AVB201.1 Microsoft Access VBA Module 1
 
Introduction to Visual Basic
Introduction to Visual Basic Introduction to Visual Basic
Introduction to Visual Basic
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
S D D Program Development Tools
S D D  Program  Development  ToolsS D D  Program  Development  Tools
S D D Program Development Tools
 
Functional programming in TypeScript
Functional programming in TypeScriptFunctional programming in TypeScript
Functional programming in TypeScript
 
Using general sub procedures
Using general sub proceduresUsing general sub procedures
Using general sub procedures
 
Introduction to Visual Basic 6.0
Introduction to Visual Basic 6.0Introduction to Visual Basic 6.0
Introduction to Visual Basic 6.0
 
Ms vb
Ms vbMs vb
Ms vb
 
PRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdfPRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdf
 
Lecture11 abap on line
Lecture11 abap on lineLecture11 abap on line
Lecture11 abap on line
 
Vb introduction.
Vb introduction.Vb introduction.
Vb introduction.
 
Mastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsMastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_arguments
 
Mvp pattern
Mvp patternMvp pattern
Mvp pattern
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
 
Example Of Import Java
Example Of Import JavaExample Of Import Java
Example Of Import Java
 
Oopp Lab Work
Oopp Lab WorkOopp Lab Work
Oopp Lab Work
 
VBA
VBAVBA
VBA
 
Electrical shop management system project report.pdf
Electrical shop management system project report.pdfElectrical shop management system project report.pdf
Electrical shop management system project report.pdf
 
Book management system
Book management systemBook management system
Book management system
 
Medicine For World
Medicine For WorldMedicine For World
Medicine For World
 

Recently uploaded

Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
shanthidl1
 
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
jackson110191
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
Kief Morris
 
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
Toru Tamaki
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
HackersList
 
WPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide DeckWPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide Deck
Lidia A.
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
Matthew Sinclair
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
Matthew Sinclair
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
Larry Smarr
 
Comparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdfComparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdf
Andrey Yasko
 
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Chris Swan
 
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdfWhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
ArgaBisma
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
huseindihon
 
Best Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdfBest Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdf
Tatiana Al-Chueyr
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
Stephanie Beckett
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
Yevgen Sysoyev
 
Measuring the Impact of Network Latency at Twitter
Measuring the Impact of Network Latency at TwitterMeasuring the Impact of Network Latency at Twitter
Measuring the Impact of Network Latency at Twitter
ScyllaDB
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
ishalveerrandhawa1
 
20240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 202420240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 2024
Matthew Sinclair
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
Mark Billinghurst
 

Recently uploaded (20)

Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
 
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
 
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
 
WPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide DeckWPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide Deck
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
 
Comparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdfComparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdf
 
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
 
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdfWhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
 
Best Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdfBest Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdf
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
 
Measuring the Impact of Network Latency at Twitter
Measuring the Impact of Network Latency at TwitterMeasuring the Impact of Network Latency at Twitter
Measuring the Impact of Network Latency at Twitter
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
 
20240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 202420240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 2024
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
 

AVB201.1 MS Access VBA Module 1

  • 1. AVB201 Visual Basic For Applications MS Access, Beginning Course P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.dhdursoassociates.com [email_address]
  • 2. OUTLINE SESSION 1: Event driven Programming in Access (3 hours). SESSION 2: VBA Language Constructs and Programming Techniques (3 hours). AVB202: Working Programmatically with Data (3 hours).
  • 4. Session 1: Event Driven Programming in Access Why VBA ? Using events and event procedures. Using VBA Editor. Event types in Access. Differentiating between functions and sub procedures. Organizing VBA code into modules. Using Variables, Scope, and Data types. Exploring and using built-in functions.
  • 5. 1.1 Why VBA ? Greatly extends the functionality of Macros. Allows customized interactions with users. Enables complex operations on records. Enables complete control over the Access Object Model Capable of making reports and forms that can make decisions based on user choices, database data, and user supplied values. Offers improved error handling capabilities. Programming is FUN !!
  • 6. 1.2 Events and Event Procedures Event is when something happens to any object in your application. Ex: User clicks a button (object) on a form (also an object). Event Procedure is a piece of VBA code that is associated with this object and this event. Since event code is programmed the event can trigger any number of actions. Ex: deleting a record and closing the form. In such event driven programming model, the user is in control of when and what should happen next in the application.
  • 7. 1.3 Using VBA Editor VBA editor is the place where you write your VBA code. Enter via code builder, CTRL G, etc. VBA editor keeps your code organized into modules, functions, procedures, and/or classes (more on module types later). You can write, document, test, compile, and debug your code with supplied tools >> explore VBA menus. We will use the VBA editor for the rest of this course.
  • 8. 1.3 Using VBA Editor Demonstration: Make “Add New” command button on a Products form.
  • 9. ..cont Exercise: Add “Delete” button to Products form and check the procedure. Explore changing the code and see how VBA automatically notifies you of certain errors. Run procedure by clicking the “Delete” command button.
  • 10. 1.4 Types of Events in Access Events in Access can be categorized into several groups: Windows (Form, Report): opening, closing, resizing. Data: making current, deleting, updating. Focus: activating, entering, exiting. Keyboard: pressing or releasing a key. Mouse: clicking a mouse button. Print: formatting, printing. Error and timing: when error occurs in code or some time passes.
  • 11. Commonly Used Events Events are normally associated with a form, report, or some control on a form. Some common form events are: On Open, On Load, Before Update, On Unload, On Current On Delete Before Delete.
  • 12. Common Control Events On Click Before Update After Update On Double Click.
  • 13. Common Report Events On Open On Activate On Close On No Data.
  • 14. Event Flow NOTE: A single user action can also trigger several events that then run in succession. For example when the user opens a form all of the following events occur: Open >> Load >> Resize >> Activate >> Current
  • 15. 1.5 Differentiating between Functions and Sub Procedures. Functions return a value to the calling code, usually providing the result of the function’s operation. Sub Procedures execute the code in the procedure but do not return any values. Both, functions and procedures, can accept multiple input values from the calling program that can be used inside their respective operations.
  • 16. ..cont Function Syntax: Function FunctionName(passed arguments) As “Data Type of Return” ..some code.. FunctionName = “Return Value” End Function
  • 17. ..cont Sub Procedure Syntax: Sub SubName(passed arguments) ..some code.. End Sub
  • 18. 1.6 Organizing VBA Code into Modules All event procedures and any other VBA code are grouped and placed into “Modules”. MS Access has 4 types of modules: Standard, Form, Report, and Class. Each form and report has its own form or report module. All event procedures associated with a particular form or report should reside in their respective module. Standard module holds any other common or non form/report specific code. Class modules support object oriented programming approach (OOP) to development.
  • 19. ..cont Exercise: Access any of the module types. In all cases you work with the same VBA editor.
  • 20. ..cont This is the place where we start writing some of our own code. Interactive Exercise : Create new standard module. Type in the following code: Function Area (Height As Double, Width As Double) As Double Area = Width * Height End Function Optionally compile code (under Debug menu). Run code in Immediate window: ?Area(3,4)
  • 21. ..cont And now try the following procedure: Sub MyLoop() Dim loopcount As Integer, i As Integer loopcount = 3 For i = 1 To loopcount Debug.Print &quot;Loop &quot;, i Next i Beep End Sub More about “For” statement in Session 2.
  • 22. 1.7 Variables, Scope, and Data Types Variables are containers that hold your data in programs. Each variable should have a type. VBA supports a wide range of data types that are not identical to data types declared on fields in tables. Knowing both groups and how to map them is essential for good programming. If you forget to assign type to a variable in VBA, then the variable is treated as a “Variant”. Variants assume data type when data is loaded in to the variable. NOTE: !! Avoid using Variants”. They slow the execution and make for poor documentation.
  • 23. Some often used data types in VBA Boolean (True or False) Currency (formatted number $56.67) Double, Single (51.145678) Integer (321) Date (#8/28/04#) String (“Any word or sentence”) Q: What are their equivalents in database tables?
  • 24. Scope of Variables (and Procedures) Scope determines where can variable be used. This depends on the place where and also how it was declared. Variables declared inside functions or subs must be declared with a Dim statement. They are always local to that sub or function..
  • 25. …cont Variables declared outside any function or sub are always global to that module. Whether they are also available to other modules, depends on what you precede their declarations with: “ Private Area As Double” would be same as “Dim Area As Double”. “ Public Area As Double” on the other hand is global to the application. NOTE: !!You can not use Public declaration inside function or sub. Use Dim ONLY.
  • 26. ..cont Functions and Procedures also have a scope. Preceding function or procedure declaration with a word “Public” or “Private” makes that function or sub available “in the module where declared only” OR they can be called (used) from any place in the application. Ex: Procedure in one module can call Public functions declared in any other module. Public and Private declarations are useful to avoid confusion with keeping track of multiple names used for variables, functions, and procedures. Similar operations on two different forms can use procedures with same name as long as they are both declared as private in their respective modules.
  • 27. ..cont Exercise: Modify the MyLoop procedure to accept the number of loops. Call the new one MyAreaLoop Call the Area function procedure from the MyAreaLoop procedure and pass it a length 0f 10 and width of I. (You will have to set up a variable of type double for area.) Run the MyAreaLoop procedure.
  • 28. ..cont Exercise: Sub MyAreaLoop(numloops As Integer) Dim loopnum As Double, i As Integer For i = 1 To numloops loopnum = i Debug.Print &quot;Area &quot;, i, Area(10, loopnum) Next i Beep End Sub
  • 29. ..cont Mini-Quiz: If you change the Area function to private does myarealoop still work? Why? How could you use global variables? Should you?
  • 30. 1.8 Built-in Functions and Procedures Beside custom made functions and procedures there are some that are built-in and part of the Access VBA language. We will see several examples in the following Sessions. “ Beep” is an example of built-in procedure and performs a single operation: It makes computer beep. Once. Built-in functions can be used anywhere in your program. Knowing what is available is essential for efficient programming so we don’t go and try to reinvent the wheel.
  • 31. Some Common built-in Functions Today = Date() returns today’s date. UCase(String) converts all letters in string to upper case. Round(3.89) rounds a value in parenthesis to nearest integer (4 here). Len(String) returns number of characters in a string. NOTE: There are close to 100 built in functions available for almost any area of data manipulation. Check some reference book for complete list or consult an Online Help in Access. We will introduce and use several in the hours ahead.
  • 32. ..cont Built-in functions are grouped into several categories: Conversion (converts one data type to another. UCase, LCase, etc..) Date/Time Financial Mathematical String Manipulation (extract parts of string, truncate, etc..) Programming (check for missing values, determine data types etc..) Domain (work on several values at once and perform statistical operations such as average, finding maximum / minimum value etc..)
  • 33. ..cont Try a couple from the immediate window:
  • 34. AVB201 – Introduction to VBA Session 1 END