Array To ADO Recordset

This is helpful in handling excel data in the same way as access data. You can easily work on recordset filters using this tip.
Function rstArrayToRecordset(arrField As Variant, arrData As Variant) As ADODB.Recordset Dim rstData As ADODB.Recordset Dim recordString As String Dim arrRecord As Variant Dim intLoop1 As Integer Dim intLoop2 As Integer ReDim arrRecord(1 To 1, 1 To UBound(arrData, 2)) Set rstData = New ADODB.Recordset For intLoop1 = 1 To UBound(arrField, 2) rstData.Fields.Append arrField(1, intLoop1), adVarChar, 500 Next intLoop1 rstData.Open For intLoop1 = 1 To UBound(arrData, 1) For intLoop2 = 1 To UBound(arrData, 2) arrRecord(1, intLoop2) = arrData(intLoop1, intLoop2) Next intLoop2 rstData.AddNew 'arrField, arrRecord rstData.Fields(0).Value = arrRecord(1, 1) rstData.Fields(1).Value = arrRecord(1, 2) rstData.Fields(2).Value = arrRecord(1, 3) rstData.Fields(3).Value = arrRecord(1, 4) rstData.Update Next intLoop1 Set rstArrayToRecordset = rstData Erase arrRecord Set rstData = Nothing End Function

| Attachment | Size |
|---|---|
| ArrayToRecordset.xls | 41.5 KB |
»
- Vishesh's blog
- Add new comment
- 3404 reads

Recent comments
5 hours 21 sec ago
8 hours 23 min ago
8 hours 46 min ago
14 hours 49 min ago
15 hours 40 min ago
1 day 6 hours ago
1 day 6 hours ago
1 day 9 hours ago
1 day 17 hours ago
2 days 13 hours ago