RecordSet without actual data behind it

A

Agoston Bejo

I would like to use an ADODB.RecordSet object to temporarily store some data
and then iterate through it. Actually it needs to be a RecordSet only
because it is a perfect choice as data structure for what I want to do, I
don't want to actually run queries or update tables with it.
It seems to me, however, that the RecordSet works only if there's a query
behind it. ADO complains about the RecordSet not being open when I try to
add rows by the AddNew function, or try to add fields to it.

Is there a way to use the RecordSet without actual database date behind it?
Or is there maybe some object in VBScript that provides the same or at least
similar functionality? (Apart from Scripting.Dictionary, which is great, but
I would like to use something more similar. :) )
 
P

Patrice

If I remember steps are :
- create the recordset
- append the fields
- open the recordset
- add data

Seesing some code that repor the problme may help...

Patrice
 
V

Veign

You need to create a disconnected recordset.

Basic structure of a disconnected recordset:

'-------------------Start Code----------------------------
'Create the Disconnected Recordset
Dim RS As Recordset
Set RS = New Recordset

'Setup the Recordset
With RS
'Make sure there is no active connection
.ActiveConnection = Nothing

'Set for client side processing
.CursorLocation = adUseClient

'Single user updates
.LockType = adLockBatchOptimistic
End With

'Add Fields and Values to Recordset
With RS.Fields
.Append "ID", adBSTR
.Append "Company", adBSTR
.Append "Description", adBSTR
End With

'Open the Recordset
RS.Open

'Populate the Data in the Recordset
With RS
.AddNew
.Fields("ID") = "ID123"
.Fields("Company") = "Some Company"
.Fields("Description") = "Description"
End With
'-------------------------End Code---------------------------
 
B

Bob Barrows [MVP]

Veign said:
You need to create a disconnected recordset.

Just a little nitpick:
He actually needs to create an "ad hoc" recordset, not "disconnected", since
"disconnected" implies that a previously connected recordset has been
disconnected by setting the ActiveConnection property to Nothing. A
disconnected recordset can be reconnected to the data source. An ad hoc
recordset, since it never was connected to a data source, cannot be
connected after it is open.

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top