Solved

How do I populate ADO recordset with no connection.

Posted on 2001-09-16
2
170 Views
Last Modified: 2006-11-17
I am using VBasic v6, ADO, and Access.

I need to pass a data record to an existing subroutine, that
I did not write.

The subroutine expects the record in the form of a
recordset object, with a single record.

I have my field values that have been computed outside of
any database.  A database with the proper table does not
exist and no connection.  I need to get my values into a
Recordset object.  I want to do something like the following.

-----

    dim RecSet as ADODB.Recordset
    dim name_list(1) as String
    dim value_list(1) as String

    name_list(0) = "Field_0"
    name_list(1) = "Field_1"
    value_list(0) = "val_0"
    value_list(1) = "val_1"

    Set RecSet = new ADODB.Recordset
    RecSet.CursorLocation = adUseClient
    Call RecSet.Open(, , adOpenStatic, adLockBatchOptimistic)
    Call RecSet.AddNew(name_list, value_list)

Alternately, instead of the "AddNew" method I could do something
like:

    ' Declare and initialize an ADODB.Field object
    Dim field_0 as ADODB.Field
    Set field_0 = new ADODB.Field
    ' Initialize the name and value properties of field_0
    Call RecSet.Fields.Append field_0

-----

This does not work.  The following Open fails.

    Call RecSet.Open(, , adOpenStatic, adLockBatchOptimistic)

Instead of adOpenStatic, I have also tried adOpenForwardOnly.

The documentation for the Open method says that Source (1st parm)
and ActiveConnection (2nd parm) are optional.  But Open() still
throws an error.  The error message says that I need a connection.
If, experimentally, I give a valid connection to an irrelevant
database, then I get an error about the missing source (first parm).

And AddNew throws an error, if I try to execute AddNew without
the Open.


So the question is, "How do I populate a recordset with data when
I have no connection to a database?"

0
Comment
Question by:Jim_S
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 150 total points
ID: 6486235
This will work:

Private Sub Command1_Click()
Dim RecSet As ADODB.Recordset

   Set RecSet = New ADODB.Recordset
   RecSet.CursorLocation = adUseClient
   RecSet.CursorType = adOpenStatic
   RecSet.LockType = adLockBatchOptimistic
   RecSet.Fields.Append "Field_0", adVarChar, 50
   RecSet.Fields.Append "Field_1", adVarChar, 50
   RecSet.Open
   Call RecSet.AddNew(Array("Field_0", "Field_1"), Array("val_0", "val_1"))

    MsgBox RecSet.RecordCount
End Sub
0
 

Author Comment

by:Jim_S
ID: 6486454
This worked.

Thank you ever so much for your prompt and
accurate answer.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question