Submitted By: Kent Finkle

Uses the GetRows method to copy a Microsoft Access recordset into a two-dimensional array.

Visual Basic
Edit|Remove
'*  Script name:    GetRows.vbs
'*  Created on:     2006-07-17 09:07:40 pm
'*  Author:         Kent Finkle
'*  Purpose:        Retrieve an Access Recordset into an array.

Option Explicit

Const adOpenStatic = 3
Const adLockOptimistic = 3

Dim objConnection
Dim objRecordSet
Dim arrTest
Dim i
Dim j

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Open "Provider= Microsoft.Jet.OLEDB.4.0; " & _
            "Data Source=C:\Scripts\Test.mdb"

objRecordSet.Open "SELECT * FROM Hardware" , objConnection, _
    adOpenStatic, adLockOptimistic

arrTest = objRecordSet.GetRows

objRecordSet.Close

objConnection.Close

For j = LBound(arrTest,2) To UBound(arrTest,2)
    For i = LBound(arrTest,1) To UBound(arrTest,1)
        Wscript.Echo arrTest(i,j)
    Next
Next