Solved

How do I populate ADO recordset with no connection.

Posted on 2001-09-16
2
160 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 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