|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
DAO: Creating A Record SetAfter youve finished defining a database table with a DAO TableDef object, you can append that object to a Database object, which adds that table to that database. After youve installed the new table, you can use the OpenRecordset method to open a record set and start working with data: Set recordset = Database.OpenRecordset (source, type, options, lockedits) Here are the arguments for OpenRecordset:
Here are the possible settings for type:
Here are the possible settings for options:
Here are the possible settings for the lockedits argument:
Lets see an example to make this clearer. In the previous few topics, weve developed a TableDef object, td, in our DAO code example, the daocode project. To append that object to the Database object we created, db, we use the Append method of the database objects TableDefs collection. After installing the table, we open it for use with the Database objects OpenRecordset method this way, creating a new DAO Recordset, which we name dbrecordset:
Sub CreateTable()
Set td = db.CreateTableDef(TableForm.Text1.Text)
Set fields(0) = td.CreateField(TableForm.Text2.Text, dbText)
Set fields(1) = td.CreateField(TableForm.Text3.Text, dbText)
td.fields.Append fields(0)
td.fields.Append fields(1)
Set dbindex = td.CreateIndex(TableForm.Text2.Text + "index")
Set IxFlds = dbindex.CreateField(TableForm.Text2.Text)
dbindex.fields.Append IxFlds
td.Indexes.Append dbindex
db.TableDefs.Append td
Set dbrecordset = db.OpenRecordset(TableForm.Text1.Text, dbOpenTable)
End Sub
In this case, were opening the new record set as a standard DAO table by passing the constant dbOpenTable. We also declare dbrecordset as a form-wide variable: Dim dbrecordset As Recordset At this point in the daocode project, then, weve created a new database with a table in it that has two fields, using the names that the user supplied for the fields and the table itself. And weve opened that table as a record set, so were ready to work with it and add data to it, which well do in later topics in this chapter. Besides creating a new database as weve done, however, the user may want to open an existing database, and well see how to do that in the next topic.
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |