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
- Login or register to post comments
- 36936 reads
Recent comments
6 years 4 weeks ago
6 years 42 weeks ago
7 years 2 weeks ago
7 years 4 weeks ago
7 years 5 weeks ago
7 years 11 weeks ago
7 years 19 weeks ago
7 years 19 weeks ago
7 years 20 weeks ago
7 years 20 weeks ago