objects in access zgeneral access objects zdata access objects (dao) yused for data management xdata...

16
Objects in Access General Access objects Data access objects (DAO) used for data management data definition data manipulation used only in code modules

Upload: osborn-briggs

Post on 19-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Objects in Access

General Access objectsData access objects (DAO)

used for data managementdata definition data manipulation

used only in code modules

Page 2: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Commonly Used Data Access Objects

DAO Description

Container Object that contains information aboutother objects

Database The open database

DBEngine The database engine

Property An object property

QueryDef A saved query

Page 3: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Commonly Used Data Access Objects

DAO Description

Recordset Set of records defined by a table or query

Relation Relationship between 2 tables or queries

Tabledef A saved table

User A user account in the database engine

Workspace An active database session

Page 4: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Using DAO

Using the current database declare an object variable of type Database use the CurrentDb function to store a

reference to the current database example

Dim dbs As Database

Set dbs = CurrentDb( )

Page 5: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Using DAO

Looping through collections uses For Each statement, similar to a For Next loop

example

Dim dbs As Database

Dim conTest As Container

Set dbs = CurrentDb()

For Each conTest In dbs.Containers

Debug.Print “Container: “; conTest.Name

Next

Page 6: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Using DAO

Recordsets records belonging to a table or query most commonly used types

table-typedynaset-typesnapshot-type

Page 7: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Using DAO

Table-type recordsets default type for any recordset object can use indexes to speed up the process of

searching for records example

Dim rec As Recordset

Set rec = db.OpenRecordset(“Students”)

Page 8: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Using DAO

Dynaset-type recordsets can contain a table or the result of a query can be edited and the results will be reflected

in the underlying tables useful if the recordset object is very large example

Set rec = db.OpenRecordset(“Students”, dbOpenDynaset)

Page 9: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Using DAO

Snapshot-type not updateable example

Set rec = db.OpenRecordset(“Students”, dbOpenSnapshot)

Page 10: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Using DAO

Method Description

rec.MoveNext Makes next record current record

MovePrevious Makes previous record current record

MoveFirst Makes first record current record

MoveLast Makes last record current record

Move n Makes n records away the currentrecord

Moving through recordsets

Page 11: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Using DAO

RecordsetClone method alternative to OpenRecordset method creates copy of recordset that can be

manipulated independently of the form’s recordset

Bookmark property what Access uses instead of record numbers stored as an array of bytes used to synchronize recordset objects which are

clones of each other

Page 12: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Using DAO

Finding records in table-type recordsets Seek method used with indexed fields

select indexed field to search onspecify search criteriaexample

rec.Index = “Price”

rec.Seek “=“, curPrice

Page 13: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Using DAO

Finding records in dynasets and snapshots Find method Works on non-indexed fields for all types of recordsets

Four methodsFindFirstFindLastFindNextFindPrevious

Page 14: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Using DAO

Method Description

Edit Copies current record to copy buffer toallow editing

AddNew Creates a new record in the copy bufferwith default values (if any)

Update Saves any changes made to the record inthe copy buffer

CancelUpdate Empties the copy buffer without savingany changes

Delete Deletes the current record

Methods to edit recordsets

Page 15: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Using DAO

Editing field values in a recordset example

rec.Edit

rec!strField = NewValue

rec.Update

Page 16: Objects in Access zGeneral Access objects zData access objects (DAO) yused for data management xdata definition xdata manipulation yused only in code modules

Using DAO

With … End With logic structure often used with DAOs, but can

be used with controls and collections