How to Create a Recordset from an Array

Hello all!

I need to create a Recordset (NO DATABASE) - Stand Alone to move though records and delete records from an Array of values.

For Example:

arrTest(0) = "A"
arrTest(1) = "B"
arrTest(2) = "C"

I want to move these values from the Array to a Recordset.

I need to loop though the Recordset and where ever I find a matching letter I need to delete it when I find a matching letter.  Once I've looped through all the records I need to write it out to a file.  The problem I was having with the Array was that if I delete an item in the middle of the Array I would have to re-number the array to loop though it later to write out the file.

Who is Participating?
vinnyd79Connect With a Mentor Commented:
If you want to use a recordset add a reference to Microsoft ActiveX data Objects Library and try something like this:

Private Sub Command1_Click()
Dim rstADO As ADODB.Recordset
Set rstADO = New ADODB.Recordset
Dim x As Long

With rstADO.Fields
  .Append "MyField", adVarChar, 10
End With


For x = 0 To UBound(arrTest)
    rstADO.Fields("MyField") = arrTest(x)
Next x

' work with records

' clean up
Set rstADO = Nothing

End Sub
If your problem is "re-number" arrays then use a collection:

    Dim c As New Collection
    Dim i As Long
    c.Add "A"
    c.Add "B"
    c.Add "C"
    For i = 1 To c.Count
        MsgBox "Index" + Str(i) + ", Value " + c(i)
    c.Remove 2
    MsgBox "2nd item deleted"
    For i = 1 To c.Count
        MsgBox "Index" + Str(i) + ", Value " + c(i)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.