Access Table Array

ivandgreat

Registered User.
Local time
Today, 15:42
Joined
Sep 18, 2012
Messages
30
Hi,

I have a table in access and i would like to create an array for two fields in that table.

How should i code it in access vba?

any one have tried this before. please help. thanks!

br,
 
Assuming you really do need an array…

Create a select query with the two fields required.
Apply any where clause or sorting you need.


Code:
Sub TestIt()
    Dim blnValid As Boolean
    Dim lngIndex As Long
    Dim vntArray As Variant

    With CurrentDb.OpenRecordset("qryMyQuery")
        If (.RecordCount) Then
            blnValid = True
            .MoveLast
            .MoveFirst
            vntArray = .GetRows(.RecordCount)
        End If
    End With
    
    If (blnValid) Then
        For lngIndex = LBound(vntArray, 2) To UBound(vntArray, 2)
            Debug.Print vntArray(0, lngIndex) & "  " & vntArray(1, lngIndex)
        Next lngIndex
    End If
    
End Sub

Chris.
 
Assuming you really do need an array…

Create a select query with the two fields required.
Apply any where clause or sorting you need.


Code:
Sub TestIt()
    Dim blnValid As Boolean
    Dim lngIndex As Long
    Dim vntArray As Variant

    With CurrentDb.OpenRecordset("qryMyQuery")
        If (.RecordCount) Then
            blnValid = True
            .MoveLast
            .MoveFirst
            vntArray = .GetRows(.RecordCount)
        End If
    End With
    
    If (blnValid) Then
        For lngIndex = LBound(vntArray, 2) To UBound(vntArray, 2)
            Debug.Print vntArray(0, lngIndex) & "  " & vntArray(1, lngIndex)
        Next lngIndex
    End If
    
End Sub

Chris.

Thanks Chris.

What if i wanted to transfer all selected array in a new table?

br,
:)
 

Users who are viewing this thread

Back
Top Bottom