Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 4 Manipulating Form Data using methods of Recordset and RecordsetClone in VBA Restrict data with filter 1 Rapid Application Development.

Similar presentations


Presentation on theme: "Lecture 4 Manipulating Form Data using methods of Recordset and RecordsetClone in VBA Restrict data with filter 1 Rapid Application Development."— Presentation transcript:

1 Lecture 4 Manipulating Form Data using methods of Recordset and RecordsetClone in VBA Restrict data with filter 1 Rapid Application Development

2 2 Topics l The ADO & DAO object models l Recordset and RecordsetClone l Methods of the Recordset object l Manipulating the Recordset using the RecordsetClone property l Restrict data by setting filter via form property and VBA

3 3 Components of a Database Application l User-interface and application code nrequest database services via the Jet database engine l The Jet database engine ncontains a set of dynamic link library (DDL) files, including a query processor and a results processor. ntranslates application’s requests into physical operations on the DB files l Data Store nfile(s) contain the data base tables of different format ncould be local or remote User Interface Data Store Database Engine

4 4 Microsoft ADO & DAO object models (1/2) l Access offers two different object models to work with recordsets, which is object-oriented interface to access a data source. nDAO (Data Access Objects) nADO (ActiveX Data Objects). The DAO model l DAO works only with Access tables. l ADO, the newer of the two, works either with MS Access and other databases via ODBC

5 5 Microsoft ADO & DAO object models (2/2) l In order to use these object libraries in your application through VBA the libraries must be referenced l Visual Basic IDE, choose Tools\References from the VBA IDE menu, and select e.g. Microsoft ActiveX Data Objects 2.8 Library option. If you don’t see that one in your References dialog box, you’ll have to scroll down to find it. l Which library should be used? nThe default is best, which is Microsoft Office 12.0 Access database engine Object Library – the equivalent of DAO nunless you need moremore

6 6 ActiveX Data Objects (ADO) l Microsoft ActiveX Data Objects (ADO) enable your client applications to access and manipulate data from a variety of sources nMS Access tables nexternal data sources, such as o Oracle oMicrosoft SQL Server. l ADO supports key features for building client/server and Web- based applications.

7 7 Data Access Objects (DAO) l DAO is an object-oriented interface of the Jet database engine l Objects: ndata objects, e.g. odatabases otables ofields noperations on database objects, e.g. oopen/close a database omodify a table’s structure oadd/update/modify/delete onavigating operations

8 8 The DAO object Model

9 9 The Access form and the Recordset object l a data form is based on a recordset via the RecordSource property na table na query Record Source

10 10 The form’s RecordsetClone property l Question: How is a recordset accessed from within a VBA code? l Answer: Using the form’s RecordsetClone property nPoints to remember about RecordsetClone oIt is a property of the form oIt refers to the recordset object to which the form is bound u e.g. CUSTOMER table l Example: If Form1 is bound to the CUSTOMER table then Form1.RecordsetClone refers to the CUSTOMER table object nForm1.RecordsetClone.Recordcount returns to the number of records of the CUSTOMER table

11 11 Moving around a form’s RecordSource using its RecordsetClone property l Form1.RecordSetClone.MoveFirst l Form1.RecordSetClone.MoveNext l Form1.RecordSetClone.MoveLast l Form1.RecordSetClone.MovePrevious

12 12 Finding a specific record l The FIND methods can only be used for locating a record in a recordset of the dynaset or snapshot type. nFindFirst nFindNext nFindLast nFindPrevious l Example: Form1.RecordsetClone.FindFirst “CustNo = 5” l Using the SEEK method nused for table-type recordset nVB uses the table’s current index to seek for a value

13 13 Methods of the Recordset Object l AddNew nForm1.RecordsetClone.AddNew l Update nForm1.RecordsetClone.Update l Example: appending a blank record and assigning field values Form1.RecordsetClone. Addnew Form1.RecordsetClone.Fields(“CustNo”)=“1234” Form1.RecordsetClone.Fields(“CustName”)=“Smith” Form1.RecordsetClone. Update

14 14 Methods of the Recordset Object l Edit Form1.RecordsetClone. Edit Form1.RecordsetClone.Fields(“CustName”) = “Bloggs” Form1.RecordsetClone.Update l Delete the current record in a RecordSet nForm1.RecordsetClone.Delete A field name

15 15 Applying a filter on a form (1/3) l A filter can be applied on a form to view only a subset of records l Use the Form property window to set a filter condition

16 16 Applying a filter on a form (2/3) l When the form is running, the set filter can be applied by clicking Filtered/Unfiltered button at the bottom of the form

17 17 Applying a filter on a form (3/3) l Dynamic filter may be set using VBA code

18 18 Summary l The ADO & DAO object models l The Recordset Object and its methods l The form’s RecordsetClone property l Restrict data by setting filter


Download ppt "Lecture 4 Manipulating Form Data using methods of Recordset and RecordsetClone in VBA Restrict data with filter 1 Rapid Application Development."

Similar presentations


Ads by Google