SlideShare a Scribd company logo
1 of 36
Sales AVB2021
Orange Coast Database Associates
Visual Basic For Applications
MS Access, Intermediate Course
P.O. Box 6142
Laguna Niguel, CA 92607
949-489-1472
http://www.dhdursoassociates.com
Sales AVB2022
Orange Coast Database Associates
 Loose association of local University
instructors and IT Professionals.
 Started in 1996
 Training
– On-site (custom classes for groups)
– Private desk side training for individuals
 Consulting
 Programming (incl. offshore)
Sales AVB2023
Post Class Contact Information
 Contact: Dan D’Urso
 Phone: 800-355-9855
 Fax: 949-485-6284
 Email: slides.1@dhdursoassociates.com
 Web Sites:
– http://www.dhdursoassociates.com
– http://ocdatabases.itgo.com
Sales AVB2024
MS Access Introductory (100 Level)
Curriculum
AIN100
AIA101
AMP110
Macros
AIN104
Reports
& Forms
AIN102
Queries
AIN100T A, B
…See also AVB201/2 intermediate level VBA
Sales AVB2025
MS Access VBA (200 Level)
Curriculum
AVB201
Introduction
AVB201
DAO/ADO
Sales AVB2026
VBA Series
 AVB201
– SESSION 1: Event driven Programming in Access
(3 hours).
– SESSION 2: VBA Language Constructs and Programming
Techniques (3 hours).
 AVB202 (This class)
– SESSION 1: Working Programmatically with Data
(3 hours).
Sales AVB2027
Session 3: Working Programmatically
with Data (AVB202)
 One 3 hour session
 Three hands on exercises – students will program
data access three ways:
– SQL via ADO connection
– ADO
– Access DAO
 Students will benefit from some prior exposure to
programming
Sales AVB2028
Session 3: Working Programmatically
with Data
 Effectively referencing Access objects and
properties.
 All About Me!
 Fundamental SQL statements.
 Referencing ADO.
 Working with ADO Connections and Recordsets.
 ADO vs. DAO.
Sales AVB2029
3.1 Effectively Referencing Access
Objects and Properties
Each object in Acccess (form, button, field, ..) has a unique
address by which it can be called. There are two operators that
you use:
the dot (.) and
the exclamation sign (!).
Example: Forms!frmProducts.Price
references the “Price” control on the form “frmProducts”.
Sales AVB20210
3.1 Effectively Referencing Access
Objects and Properties
Explanation: “frmProducts” name is preceded by a reserved
word “Forms” which identifies that following is the name of the
form (same name could be used for a report, which would then
belong to collection “Reports”).
Reserved words, other are Form, Reports, Screen and Me, are
always followed by a “!” sign.
Objects and their properties are connected with a dot “.”
character.
Sales AVB20211
..cont
NOTE: If controls or table fields are made up of more than
one word or they contain special characters, then names
must be enclosed in [ ] parenthesis.
Example: Forms!frmProducts![Product Price]
Using [ ] is safe, since they always work. If in doubt, use
them.
Sales AVB20212
3.2 All About Me!
“Me” is a shortcut for full object address.
Example: If we were accessing object (control) “Price” from a
procedure that is in form module behind the frmProducts
form, we could as easily use the
Me!Price
instead of the longer
Forms!frmProducts.Price.
“Me” is thus short for “Forms!frmProducts”.
NOTE: “Me!” always presents the address of the form or
report in which module it is used. “Me” has no meaning in
standard modules.
Sales AVB20213
3.3 Fundamental SQL Statements.
 One of the great benefits of using VBA is the ability to
work directly with the underlying database tables, fields,
and records.
 In any procedure or a function, SQL queries can be
combined with any other VBA code, all under complete
control of the programmer.
 Multiple SQL statements can execute as part of the same
procedure, to perform complex operations, as we will see
in the comprehensive example of this session.
Sales AVB20214
..cont
Introducing the subject, we review some of the fundamental
operations we perform on tables and records:
 Select (for record retrieval)
and action queries for
 Update
 Insert
 and “Delete”
of records.
Sales AVB20215
..cont (SELECT statement)
“SELECT” statement has the richest syntax and is used to
retrieve records from one or multiple tables while at the same
time filter, sort, and in other way manipulate records and
values of fields in table(s).
SELECT Products.Description From Products Where
ProductId >3 Order By Description
would retrieve Description field from table Products, records
only those that have ProductId > 3 and remaining records
would be sorted alphabetically by the description text.
NOTE: One good way to learn the syntax of SELECT is to use
the query designer and check the resulting code under the
SQL view of the designer.
Sales AVB20216
..cont (action queries)
Exercise: Make one query in query designer for each action and
look at code in SQL view.
Delete From Products Where ProductId = 2
--Will delete one record from table Products.
Insert Into Products (SKU, Description, Price)
Values (123, “Using SQL” 12.99)
--Will insert one record into table Products.
UPDATE Products SET Products.Price = 10.00
WHERE ("ProductId“ = 2)
--Will update the price field of the record with ProductId = 2.
Sales AVB20217
3.4 Data Access Models
Access has 2 object models to work with data: ADO and DAO.
ADO is the newer technology so we cover it first.
DAO on the other hand is native to Access and has
some nice features that are not part of the ADO.
Prediction is DAO will not go away, despite the availability of
ADO.
Sales AVB20218
3.4 Referencing ADO (and/or DAO)
ADO = ActiveX Data Objects. It is an external library of
functions that has to be included as a reference to the project.
If your code is misbehaving, check the reference under the
VBA editor. By default, ADO and DAO libraries are both
referenced. Check anyway!
Go: Tools >> References in the editor.
DAO = Data Access Objects. More on DAO later.
Sales AVB20219
3.4 Referencing ADO (and/or DAO)
Sales AVB20220
3.5 Working with ADO Connections
and Recordsets.
ADO is a rich object model which is best learned by
looking at examples. It lets you specify a
connection to the existing (or any other) database,
loop through the resulting recordset (in case the
SELECT statement was issued) and check for
properties of the recordset, such as: number of
records returned, where is the cursor, move back
and forth through the recordset, etc..
DEFINITION: Recordset is an in-memory copy of
the records returned by a query.
Sales AVB20221
3.5 Working with ADO Connections
and Recordsets.
Demonstration: Look at the procedure behind the
form “frmPerformance” and analyze the required
steps.
Sales AVB20222
..cont (ADO connections)
Most confusing to new ADO users are the properties used in the
recordset (rs) “Open” statement (last line).
Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection
Set cn = CurrentProject.Connection
sqlString = “Select …….”
rs.Open sqlString, cn, adOpenDynamic, adLockOptimistic
rs.Open loads results specified in sqlString into the rs recordset
and uses the database connection cn to connect to the project’s
database. But what are the last 2 parameters??
Sales AVB20223
..cont (recordset properties)
..they are ADO constants specifying properties of the opened
recordset. The following table explains.
Cursor Type Lock Type Description
adOpenForwardOnly
(fire-hose cursor, fast)
adLockReadOnly
(can’t update DB)
(Default) You can only
scroll forward through
records. Disconnected.
adOpenDynamic
(flexible, yet slow)
adLockOptimistic
(updatable back to DB)
Any movement allowed.
DB Changes by other
users are visible.
Connected to DB.
adOpenStatic adLockReadOnly Any movement allowed
but disconnected from
the DB.
Sales AVB20224
..cont (comments on the example)
 Example uses the “execute” method of the
connection object wherever we work with action
queries.
 Execute method leverages the knowledge of SQL
and does not require any choices of locks and
cursor types.
Sales AVB20225
Using ADO Methods
 Alternatively, there are Add, Update, and Delete methods of
the rs object available to perform the same thing:
1. rs.AddNew statement will insert a new record into the
existing recordset.
2. rs.Update will write record back to the database after you set
values of any fields in the record. This requires an updatable
recordset and thus you need to use the adOpenDynamic,
adLockOptimistic combo when opening the recordset.
3. rs.Delete will delete the current record. No additional call to
rs.Update is necessary.
Sales AVB20226
..cont (ADO Add and Update)
Use of ADO “Add” and “Update” methods: Insert a new
record into database table tblProducts.
Dim rs As New ADODB.Recordset
rs.Open “tblProducts”, CurrentProject.Connection,
adOpenDynamic, adLockOptimistic
rs.AddNew
rs(“Description”) = “Using SQL”
rs(“Price”) = 10.99
rs.Update
rs.Close
Set rs = Nothing
Sales AVB20227
..cont (ADO Delete)
Use of ADO “Delete” method: Delete record from database.
Dim rs As New ADODB.Recordset
sqlString = “Select * From tblProducts Where ProductId = “ & 1
rs.Open sqlString, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
If not rs.EOF Then rs.Delete
rs.Close
Set rs = Nothing
Sales AVB20228
..cont (ADO)
Exercise: Rewrite the main example with ADO
AddNew, Update, and Delete methods. In case of INSERT it
may be easier to work with.
Sales AVB20229
DAO
 DAO allows working with database schema, groups, users,
permissions, etc.. while ADO does not. Beyond that, the
differences are mostly in syntax.
 Microsoft does not plan any upgrades to DAO and
therefore using ADO is a preferred way for new projects
unless you can’t go without certain DAO features that are
omitted in ADO.
 !! Advice: Decide on one object model (ADO or DAO) and
stick to it. Mixing both in the same project, while possible
even in the same procedure or function, can lead to much
confusion in your code.
Sales AVB20230
..cont
DAO has a database object which needs to be declared. ADO
makes this instance implicitly. This tells you right away,
which model is being used.
Dim db As Database
Set db = CurrentDb
Dim rs As DAO.Recordset
Dim sqlString As String
sqlString = “Select ….”
Set rs = db.OpenRecordset (sqlString, dbOpenSnapshot)
Sales AVB20231
..cont (navigation)
DAO has much same methods as ADO for navigating
recordset’s records:
MoveFirst
MovePrevious
MoveNext
MoveLast
And properties:
EOF, BOF, and RecordCount.
NOTE: rs.RecordCount can be a very useful property in both
ADO and DAO.
Sales AVB20232
..cont (DAO Add, & Update)
“SnapShot” recordset property of previous example
is not editable. It is an equivalent of adOpenStatic,
adLockReadOnly combo in ADO.
You need to use a dbOpenDynaset property for
updating.
Sales AVB20233
..cont (DAO Add, & Update)
Use of Add and Update methods (same as in ADO but rs is a
different type of object):
Set rs = db.OpenRecordset(“tblProducts”, dbOpenDynaset)
rs.AddNew
rs(“..”) = “..” ‘set some fields
…
rs.Update
NOTE: dbOpenDynaset property is equivalent to
adOpenDynamic, adLockOptimistic combo in ADO.
Sales AVB20234
..cont (DAO Delete, Conclusion)
Use of DAO “Delete” method is analogous to Add, Update
and the treatment in ADO.
Exercise: Try rewriting the “Make Report” procedure example
with DAO. There is no better teacher than extensive practice.
Sales AVB20235
..cont (DAO Delete, Conclusion)
Both ADO and DAO object models have tens of properties,
methods, and named constants. Chances are you will never
use most of them. But if you try to do something special, it
might just be worth checking into some reference to see if
what you are trying to do is already available and/or
supported. “Access 2003 VBA Programmers Reference” from
Wrox Press has good coverage of both models.
Sales AVB20236
THE END
Thank You for Attending the Course And
Wishing You a Happy VBA Programming !!
NOTE: If interested, check our schedule for
more Intermediate and Advanced VBA
Courses (coming soon!)

More Related Content

What's hot

X++ advanced course
X++ advanced courseX++ advanced course
X++ advanced courseAlvin You
 
Sas Enterprise Guide A Revolutionary Tool
Sas Enterprise Guide A Revolutionary ToolSas Enterprise Guide A Revolutionary Tool
Sas Enterprise Guide A Revolutionary Toolsysseminar
 
Sap abap tutorial 1 (1)
Sap abap tutorial 1 (1)Sap abap tutorial 1 (1)
Sap abap tutorial 1 (1)Harshul Phadke
 
Axapta interview questions
Axapta interview questionsAxapta interview questions
Axapta interview questionsKD420
 
Practical guide to SQL basics
Practical guide to SQL basicsPractical guide to SQL basics
Practical guide to SQL basicsPavani Ganti
 
카카오커머스를 지탱하는 Angular
카카오커머스를 지탱하는 Angular카카오커머스를 지탱하는 Angular
카카오커머스를 지탱하는 Angularif kakao
 
Reading Fixed And Varying Data
Reading Fixed And Varying DataReading Fixed And Varying Data
Reading Fixed And Varying Dataguest2160992
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 
Data warehousing unit 3.2
Data warehousing unit 3.2Data warehousing unit 3.2
Data warehousing unit 3.2WE-IT TUTORIALS
 
Creating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration toolCreating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration toolRavi Kumar Lanke
 
OBIEE publisher with Report creation - Tutorial
OBIEE publisher with Report creation - TutorialOBIEE publisher with Report creation - Tutorial
OBIEE publisher with Report creation - Tutorialonlinetrainingplacements
 
Complete Sql Server querries
Complete Sql Server querriesComplete Sql Server querries
Complete Sql Server querriesIbrahim Jutt
 

What's hot (20)

Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
 
Fahri tugas cloud1
Fahri tugas cloud1Fahri tugas cloud1
Fahri tugas cloud1
 
X++ advanced course
X++ advanced courseX++ advanced course
X++ advanced course
 
Sas Enterprise Guide A Revolutionary Tool
Sas Enterprise Guide A Revolutionary ToolSas Enterprise Guide A Revolutionary Tool
Sas Enterprise Guide A Revolutionary Tool
 
Sap abap tutorial 1 (1)
Sap abap tutorial 1 (1)Sap abap tutorial 1 (1)
Sap abap tutorial 1 (1)
 
Axapta interview questions
Axapta interview questionsAxapta interview questions
Axapta interview questions
 
Practical guide to SQL basics
Practical guide to SQL basicsPractical guide to SQL basics
Practical guide to SQL basics
 
003.query
003.query003.query
003.query
 
카카오커머스를 지탱하는 Angular
카카오커머스를 지탱하는 Angular카카오커머스를 지탱하는 Angular
카카오커머스를 지탱하는 Angular
 
Proc sql tips
Proc sql tipsProc sql tips
Proc sql tips
 
Reading Fixed And Varying Data
Reading Fixed And Varying DataReading Fixed And Varying Data
Reading Fixed And Varying Data
 
Sq lite module8
Sq lite module8Sq lite module8
Sq lite module8
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
SQL
SQLSQL
SQL
 
Sq lite module6
Sq lite module6Sq lite module6
Sq lite module6
 
Data warehousing unit 3.2
Data warehousing unit 3.2Data warehousing unit 3.2
Data warehousing unit 3.2
 
Creating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration toolCreating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration tool
 
01 Microsoft Access
01 Microsoft Access01 Microsoft Access
01 Microsoft Access
 
OBIEE publisher with Report creation - Tutorial
OBIEE publisher with Report creation - TutorialOBIEE publisher with Report creation - Tutorial
OBIEE publisher with Report creation - Tutorial
 
Complete Sql Server querries
Complete Sql Server querriesComplete Sql Server querries
Complete Sql Server querries
 

Viewers also liked

Presentatie REC 250309
Presentatie REC 250309Presentatie REC 250309
Presentatie REC 250309Tim Rootsaert
 
Pharma Powerpoint 2
Pharma Powerpoint 2Pharma Powerpoint 2
Pharma Powerpoint 2guest4a9aba
 
Resume Portfolio Linkedin 01 2009
Resume Portfolio Linkedin 01 2009Resume Portfolio Linkedin 01 2009
Resume Portfolio Linkedin 01 2009pulamajor
 
Creating a Photo Story With Soundslides
Creating a Photo Story With SoundslidesCreating a Photo Story With Soundslides
Creating a Photo Story With SoundslidesRyan Thornburg
 
青年創業及圓夢網 創業稅務大小事【創業懶人包 】
青年創業及圓夢網 創業稅務大小事【創業懶人包 】青年創業及圓夢網 創業稅務大小事【創業懶人包 】
青年創業及圓夢網 創業稅務大小事【創業懶人包 】RICK Lin
 
My Logo Portfolio
My Logo PortfolioMy Logo Portfolio
My Logo Portfoliobeth7865
 
Comic Book
Comic BookComic Book
Comic BookThomasdl
 
The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...
The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...
The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...Andres Agostini, Future Knowledgist
 
Futuretronium Book 100.0 (The Revolution II)! By Andres Agostini at http://li...
Futuretronium Book 100.0 (The Revolution II)! By Andres Agostini at http://li...Futuretronium Book 100.0 (The Revolution II)! By Andres Agostini at http://li...
Futuretronium Book 100.0 (The Revolution II)! By Andres Agostini at http://li...Andres Agostini, Future Knowledgist
 
Displays
DisplaysDisplays
Displaysspecfab
 
Ikregeer Overheid20
Ikregeer   Overheid20Ikregeer   Overheid20
Ikregeer Overheid20BZK
 
Dutch Overheid20
Dutch   Overheid20Dutch   Overheid20
Dutch Overheid20BZK
 
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 DataRyan Thornburg
 
eParticipation in The Netherlands
eParticipation in The NetherlandseParticipation in The Netherlands
eParticipation in The NetherlandsBZK
 
Tutorial: Your First Reporting Assignment
Tutorial: Your First Reporting AssignmentTutorial: Your First Reporting Assignment
Tutorial: Your First Reporting AssignmentRyan Thornburg
 
Course Catalog
Course CatalogCourse Catalog
Course CatalogDan D'Urso
 

Viewers also liked (20)

Test 1
Test 1Test 1
Test 1
 
Presentatie REC 250309
Presentatie REC 250309Presentatie REC 250309
Presentatie REC 250309
 
Pharma Powerpoint 2
Pharma Powerpoint 2Pharma Powerpoint 2
Pharma Powerpoint 2
 
K.l. reich
K.l. reichK.l. reich
K.l. reich
 
IntelliStick
IntelliStickIntelliStick
IntelliStick
 
Resume Portfolio Linkedin 01 2009
Resume Portfolio Linkedin 01 2009Resume Portfolio Linkedin 01 2009
Resume Portfolio Linkedin 01 2009
 
Creating a Photo Story With Soundslides
Creating a Photo Story With SoundslidesCreating a Photo Story With Soundslides
Creating a Photo Story With Soundslides
 
青年創業及圓夢網 創業稅務大小事【創業懶人包 】
青年創業及圓夢網 創業稅務大小事【創業懶人包 】青年創業及圓夢網 創業稅務大小事【創業懶人包 】
青年創業及圓夢網 創業稅務大小事【創業懶人包 】
 
My Logo Portfolio
My Logo PortfolioMy Logo Portfolio
My Logo Portfolio
 
Comic Book
Comic BookComic Book
Comic Book
 
The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...
The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...
The Future-Present Interrelationship: Reflections, Thoughts, And Ideas, As We...
 
Futuretronium Book 100.0 (The Revolution II)! By Andres Agostini at http://li...
Futuretronium Book 100.0 (The Revolution II)! By Andres Agostini at http://li...Futuretronium Book 100.0 (The Revolution II)! By Andres Agostini at http://li...
Futuretronium Book 100.0 (The Revolution II)! By Andres Agostini at http://li...
 
Displays
DisplaysDisplays
Displays
 
Ikregeer Overheid20
Ikregeer   Overheid20Ikregeer   Overheid20
Ikregeer Overheid20
 
Dutch Overheid20
Dutch   Overheid20Dutch   Overheid20
Dutch Overheid20
 
minggu 2
minggu 2minggu 2
minggu 2
 
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
 
eParticipation in The Netherlands
eParticipation in The NetherlandseParticipation in The Netherlands
eParticipation in The Netherlands
 
Tutorial: Your First Reporting Assignment
Tutorial: Your First Reporting AssignmentTutorial: Your First Reporting Assignment
Tutorial: Your First Reporting Assignment
 
Course Catalog
Course CatalogCourse Catalog
Course Catalog
 

Similar to AVB202 Intermediate Microsoft Access VBA

Overview of atg framework
Overview of atg frameworkOverview of atg framework
Overview of atg frameworkYousuf Roushan
 
3 tier architecture in asp.net
3 tier architecture in asp.net3 tier architecture in asp.net
3 tier architecture in asp.netRavi Bansal
 
Flavours - Classic/Technical BDD
Flavours - Classic/Technical BDDFlavours - Classic/Technical BDD
Flavours - Classic/Technical BDDDavid Harrison
 
MaxTECH Technical Training - Maximo Custom Audit Solution
MaxTECH Technical Training - Maximo Custom Audit SolutionMaxTECH Technical Training - Maximo Custom Audit Solution
MaxTECH Technical Training - Maximo Custom Audit SolutionHelen Fisher
 
Bt0082, visual basic
Bt0082, visual basicBt0082, visual basic
Bt0082, visual basicsmumbahelp
 
Database Management System - SQL beginner Training
Database Management System - SQL beginner Training Database Management System - SQL beginner Training
Database Management System - SQL beginner Training Moutasm Tamimi
 
CaseStudy-MohammedImranAlam-Xcelsius
CaseStudy-MohammedImranAlam-XcelsiusCaseStudy-MohammedImranAlam-Xcelsius
CaseStudy-MohammedImranAlam-XcelsiusMohammed Imran Alam
 
Introduction To Work Item Customisation
Introduction To Work Item CustomisationIntroduction To Work Item Customisation
Introduction To Work Item Customisationwbarthol
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
TSQL Coding Guidelines
TSQL Coding GuidelinesTSQL Coding Guidelines
TSQL Coding GuidelinesChris Adkin
 
Analysis Services en SQL Server 2008
Analysis Services en SQL Server 2008Analysis Services en SQL Server 2008
Analysis Services en SQL Server 2008Eduardo Castro
 
Incremental View Maintenance with Coral, DBT, and Iceberg
Incremental View Maintenance with Coral, DBT, and IcebergIncremental View Maintenance with Coral, DBT, and Iceberg
Incremental View Maintenance with Coral, DBT, and IcebergWalaa Eldin Moustafa
 
Web Developer make the most out of your Database !
Web Developer make the most out of your Database !Web Developer make the most out of your Database !
Web Developer make the most out of your Database !Jean-Marc Desvaux
 
IUA 2001 Creative Techniques for Application Tuning
IUA 2001   Creative Techniques for Application TuningIUA 2001   Creative Techniques for Application Tuning
IUA 2001 Creative Techniques for Application TuningGary Cherlet
 
A Matter Of Form: Access Forms to make reporting a snap (or a click)
A Matter Of Form: Access Forms to make reporting a snap (or a click)A Matter Of Form: Access Forms to make reporting a snap (or a click)
A Matter Of Form: Access Forms to make reporting a snap (or a click)Alan Manifold
 
Architecture Specification - Visual Modeling Tool
Architecture Specification - Visual Modeling ToolArchitecture Specification - Visual Modeling Tool
Architecture Specification - Visual Modeling ToolAdriaan Venter
 
Taking Apex and Visualforce Above and Beyond
Taking Apex and Visualforce Above and BeyondTaking Apex and Visualforce Above and Beyond
Taking Apex and Visualforce Above and BeyondSalesforce Developers
 

Similar to AVB202 Intermediate Microsoft Access VBA (20)

Overview of atg framework
Overview of atg frameworkOverview of atg framework
Overview of atg framework
 
3 tier architecture in asp.net
3 tier architecture in asp.net3 tier architecture in asp.net
3 tier architecture in asp.net
 
Flavours - Classic/Technical BDD
Flavours - Classic/Technical BDDFlavours - Classic/Technical BDD
Flavours - Classic/Technical BDD
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
Linq to sql
Linq to sqlLinq to sql
Linq to sql
 
MaxTECH Technical Training - Maximo Custom Audit Solution
MaxTECH Technical Training - Maximo Custom Audit SolutionMaxTECH Technical Training - Maximo Custom Audit Solution
MaxTECH Technical Training - Maximo Custom Audit Solution
 
Bt0082, visual basic
Bt0082, visual basicBt0082, visual basic
Bt0082, visual basic
 
Database Management System - SQL beginner Training
Database Management System - SQL beginner Training Database Management System - SQL beginner Training
Database Management System - SQL beginner Training
 
CaseStudy-MohammedImranAlam-Xcelsius
CaseStudy-MohammedImranAlam-XcelsiusCaseStudy-MohammedImranAlam-Xcelsius
CaseStudy-MohammedImranAlam-Xcelsius
 
Introduction To Work Item Customisation
Introduction To Work Item CustomisationIntroduction To Work Item Customisation
Introduction To Work Item Customisation
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
TSQL Coding Guidelines
TSQL Coding GuidelinesTSQL Coding Guidelines
TSQL Coding Guidelines
 
Analysis Services en SQL Server 2008
Analysis Services en SQL Server 2008Analysis Services en SQL Server 2008
Analysis Services en SQL Server 2008
 
Incremental View Maintenance with Coral, DBT, and Iceberg
Incremental View Maintenance with Coral, DBT, and IcebergIncremental View Maintenance with Coral, DBT, and Iceberg
Incremental View Maintenance with Coral, DBT, and Iceberg
 
Web Developer make the most out of your Database !
Web Developer make the most out of your Database !Web Developer make the most out of your Database !
Web Developer make the most out of your Database !
 
IUA 2001 Creative Techniques for Application Tuning
IUA 2001   Creative Techniques for Application TuningIUA 2001   Creative Techniques for Application Tuning
IUA 2001 Creative Techniques for Application Tuning
 
CAD Report
CAD ReportCAD Report
CAD Report
 
A Matter Of Form: Access Forms to make reporting a snap (or a click)
A Matter Of Form: Access Forms to make reporting a snap (or a click)A Matter Of Form: Access Forms to make reporting a snap (or a click)
A Matter Of Form: Access Forms to make reporting a snap (or a click)
 
Architecture Specification - Visual Modeling Tool
Architecture Specification - Visual Modeling ToolArchitecture Specification - Visual Modeling Tool
Architecture Specification - Visual Modeling Tool
 
Taking Apex and Visualforce Above and Beyond
Taking Apex and Visualforce Above and BeyondTaking Apex and Visualforce Above and Beyond
Taking Apex and Visualforce Above and Beyond
 

More from Dan D'Urso

SQL201S Accelerated Introduction to MySQL Queries
SQL201S Accelerated Introduction to MySQL QueriesSQL201S Accelerated Introduction to MySQL Queries
SQL201S Accelerated Introduction to MySQL QueriesDan D'Urso
 
LCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with LucidchartLCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with LucidchartDan D'Urso
 
Database Normalization
Database NormalizationDatabase Normalization
Database NormalizationDan D'Urso
 
VIS201d Visio Database Diagramming
VIS201d Visio Database DiagrammingVIS201d Visio Database Diagramming
VIS201d Visio Database DiagrammingDan D'Urso
 
PRJ101a Project 2013 Accelerated
PRJ101a Project 2013 AcceleratedPRJ101a Project 2013 Accelerated
PRJ101a Project 2013 AcceleratedDan D'Urso
 
PRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic TrainingPRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic TrainingDan D'Urso
 
Introduction to coding using Python
Introduction to coding using PythonIntroduction to coding using Python
Introduction to coding using PythonDan D'Urso
 
Stem conference
Stem conferenceStem conference
Stem conferenceDan D'Urso
 
SQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL DesignSQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL DesignDan D'Urso
 
Microsoft access self joins
Microsoft access self joinsMicrosoft access self joins
Microsoft access self joinsDan D'Urso
 
SQL302 Intermediate SQL
SQL302 Intermediate SQLSQL302 Intermediate SQL
SQL302 Intermediate SQLDan D'Urso
 
AIN106 Access Reporting and Analysis
AIN106 Access Reporting and AnalysisAIN106 Access Reporting and Analysis
AIN106 Access Reporting and AnalysisDan D'Urso
 
SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3Dan D'Urso
 
SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2Dan D'Urso
 
Course Catalog
Course CatalogCourse Catalog
Course CatalogDan D'Urso
 
SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1Dan D'Urso
 
SQL212 Oracle SQL Manual
SQL212 Oracle SQL ManualSQL212 Oracle SQL Manual
SQL212 Oracle SQL ManualDan D'Urso
 
SQL201W MySQL SQL Manual
SQL201W MySQL SQL ManualSQL201W MySQL SQL Manual
SQL201W MySQL SQL ManualDan D'Urso
 
SQL206 SQL Median
SQL206 SQL MedianSQL206 SQL Median
SQL206 SQL MedianDan D'Urso
 

More from Dan D'Urso (20)

SQL201S Accelerated Introduction to MySQL Queries
SQL201S Accelerated Introduction to MySQL QueriesSQL201S Accelerated Introduction to MySQL Queries
SQL201S Accelerated Introduction to MySQL Queries
 
LCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with LucidchartLCD201d Database Diagramming with Lucidchart
LCD201d Database Diagramming with Lucidchart
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
 
VIS201d Visio Database Diagramming
VIS201d Visio Database DiagrammingVIS201d Visio Database Diagramming
VIS201d Visio Database Diagramming
 
PRJ101a Project 2013 Accelerated
PRJ101a Project 2013 AcceleratedPRJ101a Project 2013 Accelerated
PRJ101a Project 2013 Accelerated
 
PRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic TrainingPRJ101xl Project Libre Basic Training
PRJ101xl Project Libre Basic Training
 
Introduction to coding using Python
Introduction to coding using PythonIntroduction to coding using Python
Introduction to coding using Python
 
Stem conference
Stem conferenceStem conference
Stem conference
 
SQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL DesignSQL200A Microsoft Access SQL Design
SQL200A Microsoft Access SQL Design
 
Microsoft access self joins
Microsoft access self joinsMicrosoft access self joins
Microsoft access self joins
 
SQL302 Intermediate SQL
SQL302 Intermediate SQLSQL302 Intermediate SQL
SQL302 Intermediate SQL
 
AIN106 Access Reporting and Analysis
AIN106 Access Reporting and AnalysisAIN106 Access Reporting and Analysis
AIN106 Access Reporting and Analysis
 
SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3SQL302 Intermediate SQL Workshop 3
SQL302 Intermediate SQL Workshop 3
 
SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2SQL302 Intermediate SQL Workshop 2
SQL302 Intermediate SQL Workshop 2
 
Course Catalog
Course CatalogCourse Catalog
Course Catalog
 
SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1SQL302 Intermediate SQL Workshop 1
SQL302 Intermediate SQL Workshop 1
 
SQL212 Oracle SQL Manual
SQL212 Oracle SQL ManualSQL212 Oracle SQL Manual
SQL212 Oracle SQL Manual
 
SQL201W MySQL SQL Manual
SQL201W MySQL SQL ManualSQL201W MySQL SQL Manual
SQL201W MySQL SQL Manual
 
AIN100
AIN100AIN100
AIN100
 
SQL206 SQL Median
SQL206 SQL MedianSQL206 SQL Median
SQL206 SQL Median
 

Recently uploaded

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Recently uploaded (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

AVB202 Intermediate Microsoft Access VBA

  • 1. Sales AVB2021 Orange Coast Database Associates Visual Basic For Applications MS Access, Intermediate Course P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.dhdursoassociates.com
  • 2. Sales AVB2022 Orange Coast Database Associates  Loose association of local University instructors and IT Professionals.  Started in 1996  Training – On-site (custom classes for groups) – Private desk side training for individuals  Consulting  Programming (incl. offshore)
  • 3. Sales AVB2023 Post Class Contact Information  Contact: Dan D’Urso  Phone: 800-355-9855  Fax: 949-485-6284  Email: slides.1@dhdursoassociates.com  Web Sites: – http://www.dhdursoassociates.com – http://ocdatabases.itgo.com
  • 4. Sales AVB2024 MS Access Introductory (100 Level) Curriculum AIN100 AIA101 AMP110 Macros AIN104 Reports & Forms AIN102 Queries AIN100T A, B …See also AVB201/2 intermediate level VBA
  • 5. Sales AVB2025 MS Access VBA (200 Level) Curriculum AVB201 Introduction AVB201 DAO/ADO
  • 6. Sales AVB2026 VBA Series  AVB201 – SESSION 1: Event driven Programming in Access (3 hours). – SESSION 2: VBA Language Constructs and Programming Techniques (3 hours).  AVB202 (This class) – SESSION 1: Working Programmatically with Data (3 hours).
  • 7. Sales AVB2027 Session 3: Working Programmatically with Data (AVB202)  One 3 hour session  Three hands on exercises – students will program data access three ways: – SQL via ADO connection – ADO – Access DAO  Students will benefit from some prior exposure to programming
  • 8. Sales AVB2028 Session 3: Working Programmatically with Data  Effectively referencing Access objects and properties.  All About Me!  Fundamental SQL statements.  Referencing ADO.  Working with ADO Connections and Recordsets.  ADO vs. DAO.
  • 9. Sales AVB2029 3.1 Effectively Referencing Access Objects and Properties Each object in Acccess (form, button, field, ..) has a unique address by which it can be called. There are two operators that you use: the dot (.) and the exclamation sign (!). Example: Forms!frmProducts.Price references the “Price” control on the form “frmProducts”.
  • 10. Sales AVB20210 3.1 Effectively Referencing Access Objects and Properties Explanation: “frmProducts” name is preceded by a reserved word “Forms” which identifies that following is the name of the form (same name could be used for a report, which would then belong to collection “Reports”). Reserved words, other are Form, Reports, Screen and Me, are always followed by a “!” sign. Objects and their properties are connected with a dot “.” character.
  • 11. Sales AVB20211 ..cont NOTE: If controls or table fields are made up of more than one word or they contain special characters, then names must be enclosed in [ ] parenthesis. Example: Forms!frmProducts![Product Price] Using [ ] is safe, since they always work. If in doubt, use them.
  • 12. Sales AVB20212 3.2 All About Me! “Me” is a shortcut for full object address. Example: If we were accessing object (control) “Price” from a procedure that is in form module behind the frmProducts form, we could as easily use the Me!Price instead of the longer Forms!frmProducts.Price. “Me” is thus short for “Forms!frmProducts”. NOTE: “Me!” always presents the address of the form or report in which module it is used. “Me” has no meaning in standard modules.
  • 13. Sales AVB20213 3.3 Fundamental SQL Statements.  One of the great benefits of using VBA is the ability to work directly with the underlying database tables, fields, and records.  In any procedure or a function, SQL queries can be combined with any other VBA code, all under complete control of the programmer.  Multiple SQL statements can execute as part of the same procedure, to perform complex operations, as we will see in the comprehensive example of this session.
  • 14. Sales AVB20214 ..cont Introducing the subject, we review some of the fundamental operations we perform on tables and records:  Select (for record retrieval) and action queries for  Update  Insert  and “Delete” of records.
  • 15. Sales AVB20215 ..cont (SELECT statement) “SELECT” statement has the richest syntax and is used to retrieve records from one or multiple tables while at the same time filter, sort, and in other way manipulate records and values of fields in table(s). SELECT Products.Description From Products Where ProductId >3 Order By Description would retrieve Description field from table Products, records only those that have ProductId > 3 and remaining records would be sorted alphabetically by the description text. NOTE: One good way to learn the syntax of SELECT is to use the query designer and check the resulting code under the SQL view of the designer.
  • 16. Sales AVB20216 ..cont (action queries) Exercise: Make one query in query designer for each action and look at code in SQL view. Delete From Products Where ProductId = 2 --Will delete one record from table Products. Insert Into Products (SKU, Description, Price) Values (123, “Using SQL” 12.99) --Will insert one record into table Products. UPDATE Products SET Products.Price = 10.00 WHERE ("ProductId“ = 2) --Will update the price field of the record with ProductId = 2.
  • 17. Sales AVB20217 3.4 Data Access Models Access has 2 object models to work with data: ADO and DAO. ADO is the newer technology so we cover it first. DAO on the other hand is native to Access and has some nice features that are not part of the ADO. Prediction is DAO will not go away, despite the availability of ADO.
  • 18. Sales AVB20218 3.4 Referencing ADO (and/or DAO) ADO = ActiveX Data Objects. It is an external library of functions that has to be included as a reference to the project. If your code is misbehaving, check the reference under the VBA editor. By default, ADO and DAO libraries are both referenced. Check anyway! Go: Tools >> References in the editor. DAO = Data Access Objects. More on DAO later.
  • 19. Sales AVB20219 3.4 Referencing ADO (and/or DAO)
  • 20. Sales AVB20220 3.5 Working with ADO Connections and Recordsets. ADO is a rich object model which is best learned by looking at examples. It lets you specify a connection to the existing (or any other) database, loop through the resulting recordset (in case the SELECT statement was issued) and check for properties of the recordset, such as: number of records returned, where is the cursor, move back and forth through the recordset, etc.. DEFINITION: Recordset is an in-memory copy of the records returned by a query.
  • 21. Sales AVB20221 3.5 Working with ADO Connections and Recordsets. Demonstration: Look at the procedure behind the form “frmPerformance” and analyze the required steps.
  • 22. Sales AVB20222 ..cont (ADO connections) Most confusing to new ADO users are the properties used in the recordset (rs) “Open” statement (last line). Dim rs As New ADODB.Recordset Dim cn As New ADODB.Connection Set cn = CurrentProject.Connection sqlString = “Select …….” rs.Open sqlString, cn, adOpenDynamic, adLockOptimistic rs.Open loads results specified in sqlString into the rs recordset and uses the database connection cn to connect to the project’s database. But what are the last 2 parameters??
  • 23. Sales AVB20223 ..cont (recordset properties) ..they are ADO constants specifying properties of the opened recordset. The following table explains. Cursor Type Lock Type Description adOpenForwardOnly (fire-hose cursor, fast) adLockReadOnly (can’t update DB) (Default) You can only scroll forward through records. Disconnected. adOpenDynamic (flexible, yet slow) adLockOptimistic (updatable back to DB) Any movement allowed. DB Changes by other users are visible. Connected to DB. adOpenStatic adLockReadOnly Any movement allowed but disconnected from the DB.
  • 24. Sales AVB20224 ..cont (comments on the example)  Example uses the “execute” method of the connection object wherever we work with action queries.  Execute method leverages the knowledge of SQL and does not require any choices of locks and cursor types.
  • 25. Sales AVB20225 Using ADO Methods  Alternatively, there are Add, Update, and Delete methods of the rs object available to perform the same thing: 1. rs.AddNew statement will insert a new record into the existing recordset. 2. rs.Update will write record back to the database after you set values of any fields in the record. This requires an updatable recordset and thus you need to use the adOpenDynamic, adLockOptimistic combo when opening the recordset. 3. rs.Delete will delete the current record. No additional call to rs.Update is necessary.
  • 26. Sales AVB20226 ..cont (ADO Add and Update) Use of ADO “Add” and “Update” methods: Insert a new record into database table tblProducts. Dim rs As New ADODB.Recordset rs.Open “tblProducts”, CurrentProject.Connection, adOpenDynamic, adLockOptimistic rs.AddNew rs(“Description”) = “Using SQL” rs(“Price”) = 10.99 rs.Update rs.Close Set rs = Nothing
  • 27. Sales AVB20227 ..cont (ADO Delete) Use of ADO “Delete” method: Delete record from database. Dim rs As New ADODB.Recordset sqlString = “Select * From tblProducts Where ProductId = “ & 1 rs.Open sqlString, CurrentProject.Connection, adOpenDynamic, adLockOptimistic If not rs.EOF Then rs.Delete rs.Close Set rs = Nothing
  • 28. Sales AVB20228 ..cont (ADO) Exercise: Rewrite the main example with ADO AddNew, Update, and Delete methods. In case of INSERT it may be easier to work with.
  • 29. Sales AVB20229 DAO  DAO allows working with database schema, groups, users, permissions, etc.. while ADO does not. Beyond that, the differences are mostly in syntax.  Microsoft does not plan any upgrades to DAO and therefore using ADO is a preferred way for new projects unless you can’t go without certain DAO features that are omitted in ADO.  !! Advice: Decide on one object model (ADO or DAO) and stick to it. Mixing both in the same project, while possible even in the same procedure or function, can lead to much confusion in your code.
  • 30. Sales AVB20230 ..cont DAO has a database object which needs to be declared. ADO makes this instance implicitly. This tells you right away, which model is being used. Dim db As Database Set db = CurrentDb Dim rs As DAO.Recordset Dim sqlString As String sqlString = “Select ….” Set rs = db.OpenRecordset (sqlString, dbOpenSnapshot)
  • 31. Sales AVB20231 ..cont (navigation) DAO has much same methods as ADO for navigating recordset’s records: MoveFirst MovePrevious MoveNext MoveLast And properties: EOF, BOF, and RecordCount. NOTE: rs.RecordCount can be a very useful property in both ADO and DAO.
  • 32. Sales AVB20232 ..cont (DAO Add, & Update) “SnapShot” recordset property of previous example is not editable. It is an equivalent of adOpenStatic, adLockReadOnly combo in ADO. You need to use a dbOpenDynaset property for updating.
  • 33. Sales AVB20233 ..cont (DAO Add, & Update) Use of Add and Update methods (same as in ADO but rs is a different type of object): Set rs = db.OpenRecordset(“tblProducts”, dbOpenDynaset) rs.AddNew rs(“..”) = “..” ‘set some fields … rs.Update NOTE: dbOpenDynaset property is equivalent to adOpenDynamic, adLockOptimistic combo in ADO.
  • 34. Sales AVB20234 ..cont (DAO Delete, Conclusion) Use of DAO “Delete” method is analogous to Add, Update and the treatment in ADO. Exercise: Try rewriting the “Make Report” procedure example with DAO. There is no better teacher than extensive practice.
  • 35. Sales AVB20235 ..cont (DAO Delete, Conclusion) Both ADO and DAO object models have tens of properties, methods, and named constants. Chances are you will never use most of them. But if you try to do something special, it might just be worth checking into some reference to see if what you are trying to do is already available and/or supported. “Access 2003 VBA Programmers Reference” from Wrox Press has good coverage of both models.
  • 36. Sales AVB20236 THE END Thank You for Attending the Course And Wishing You a Happy VBA Programming !! NOTE: If interested, check our schedule for more Intermediate and Advanced VBA Courses (coming soon!)

Editor's Notes

  1. Demo: Procedure behind the “Make Report” button calculates performance (sales) based commissions for all sales people and stores results in a separate table. These results are further used by a query that generates a performance report.
  2. Demo: Procedure behind the “Make Report” button calculates performance (sales) based commissions for all sales people and stores results in a separate table. These results are further used by a query that generates a performance report.