• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

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:

Array:
arrTest(0) = "A"
arrTest(1) = "B"
arrTest(2) = "C"
etc....

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.

Thanks,
smithmrk
0
smithmrk
Asked:
smithmrk
1 Solution
 
rettiseertCommented:
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)
    Next
   
    c.Remove 2
    MsgBox "2nd item deleted"
   
    For i = 1 To c.Count
        MsgBox "Index" + Str(i) + ", Value " + c(i)
    Next
0
 
vinnyd79Commented:
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

rstADO.Open

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

' work with records

' clean up
rstADO.Close
Set rstADO = Nothing

End Sub
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now