[AccessD] Access Array in VB

MartyConnelly martyconnelly at shaw.ca
Tue Jun 13 12:48:45 CDT 2006


This may not be what you want but is a starter.
You can pass the array to VB as a Variant
essentially a pointer to the start of the array.
Here is an example, there are other methods,
if you are going to have modifiable dimensions of the array.

GetRows Method Example (Microsoft Access)

The following example uses the GetRows method to return
a two-dimensional array containing all rows of data in a Recordset object:

Sub RowsArray()
    Dim dbs As Database, rst As Recordset, strSQL As String
    Dim varRecords As Variant, intI As Integer, intJ As Integer
   
    ' Return reference to current database.
    Set dbs = CurrentDb
    ' Build SQL statement that returns specified fields.
    strSQL = "SELECT FirstName, LastName, HireDate " _
        & "FROM Employees"
    ' Open dynaset-type Recordset object.
    Set rst = dbs.OpenRecordset(strSQL)
    ' Move to end of recordset.
    rst.MoveLast
    ' Return to first record.

    rst.MoveFirst
    ' Return all rows into array.
    varRecords = rst.GetRows(rst.RecordCount)
    ' Find upper bound of second dimension.
    For intI = 0 To UBound(varRecords, 2)
        Debug.Print
        ' Find upper bound of first dimension.
        For intJ = 0 To UBound(varRecords, 1)
            ' Print data from each row in array.
            Debug.Print varRecords(intJ, intI)
        Next intJ
    Next intI
    rst.Close
    Set dbs = Nothing
End Sub





Kaup, Chester wrote:

>Is there a way in VB to access (get to rows and columns) an array stored
>in MS Access? A person working in VB asked and I have no idea. You ideas
>please. Thanks.
>
> 
>
>Chester Kaup
>
>Engineering Technician
>
>Kinder Morgan CO2 Company, LLP
>
>Office (432) 688-3797
>
>FAX (432) 688-3799
>
> 
>
> 
>
>No trees were killed in the sending of this message. However a large
>number of electrons were terribly inconvenienced.
>
> 
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada




More information about the AccessD mailing list