Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I populate ADO recordset with no connection.

Posted on 2001-09-16
2
Medium Priority
?
187 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 600 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…
Suggested Courses

610 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