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
- 36631 reads
Recent comments
5 years 36 weeks ago
6 years 22 weeks ago
6 years 34 weeks ago
6 years 37 weeks ago
6 years 38 weeks ago
6 years 43 weeks ago
6 years 52 weeks ago
7 years 2 days ago
7 years 3 days ago
7 years 3 days ago