A dynamic Recordset object never uses a connection object and has nothing to
do with any sort of external data storage.
To implement a dynamic Recordset, you never associate it with a Connection object.
Instead, you dynamically define its structure by adding Field objects to its Fields collection.
It is then up to the application (perhaps with the user's help) to populate the Recordset
with rows and manipulate its data.
Your code should take the following steps to implement a dynamic Recordset:
-
Determine ahead of time the field structure that you want for each row of the dynamic
Recordset.
-
Declare a Recordset object variable, but don't associate it with a Connection.
-
Repeat the following steps for each field that you want in the Recordset's structure:
• Call the Append method of the Recordset object's Fields collection to add
the Field to the Recordset's Fields.
• In the first and second arguments of the Append method, set the Field object's
Name and Type properties, respectively. If the Field has a type that can vary in
size (such as BSTR, a Basic String type), also set its AssignedSize property in the
third argument.
• Repeat these steps for each Field that you want to have in the Recordset.
-
Call the Recordset object's Open method.
-
Load the Recordset with initial data through user edits and/or your own processing logic.
Use the Recordset techniques discussed in this chapter.
-
Manipulate the data in the Recordset through user edits and/or your own processing logic.
Again, use the Recordset techniques discussed in this chapter.
Listing 8.14 gives an example of code that implements a dynamic Recordset
with offline processing.
LISTING 8.14
CODE THAT IMPLEMENTS A DYNAMIC RECORDSET
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Fields.Append "FirstName", adBSTR, 25
rs.Fields.Append "LastName", adBSTR, 25
rs.Open
'After this point, programming is identical
'to manipulating any other type of
'ADO Recordset object