Multidimensional Arrays

Multidimensional Arrays

In Access it is possible to create an array with more than one dimension.

Dim myIntegerArray() as Integer
ReDim myIntegerArray(7,52)

In the above code, we tell Access to create an array of 364 elements (7×52).

In the code below, we create a 3×5 array, fill certain elements with values and print it to the immediate window.

Sub MultiDimendionalArrays()
Dim myIntegerArray() As Integer
Dim element As Variant
ReDim myIntegerArray(3, 5)
'we create a 3 x 5 array

myIntegerArray(0, 0) = 1
myIntegerArray(1, 2) = 2
myIntegerArray(3, 3) = 3
myIntegerArray(2, 3) = 4
myIntegerArray(3, 3) = 5
myIntegerArray(3, 1) = 6
'We fill some of the array elements with values
'Any we don't fill will get a default value of
'0 because the array is of type integer

For Each element In myIntegerArray
    Debug.Print element
    'here we print the array to the immediate window
Next


End Sub

The result of running the above code will be:

1
0
0
0
0
0
0
6
0
2
0
0
0
0
4
5
0
0
0
0
0
0
0
0

 

Related Posts

Loops – For Each
Working With Arrays 1
Working With Arrays 2

As always, a site wouldn't be anything without its users so please feel free to comment! We welcome any comments you have on the material and any suggestions you may have for future content.


In our humble opinion, it is worth commenting just so you can play with Fun Captcha below!

Leave a Reply

Your email address will not be published. Required fields are marked *