Problem with 2-dimensional array

D

Depez9

Hi,

Can someone tell me why this code only shows 1 filled row and leaves
the rest blank (number of rows is correct but they are all blank but
1).

Public Function Addresses()
Dim ol As Object
Dim olns As Object
Dim objFolder As Object
Dim objAllContacts As Object
Dim Contact As Object
Dim MyAddressAs String

Set ol = New Outlook.Application

Set olns = ol.GetNamespace("MAPI")

Set MyFolder1 = olns.Folders("Public Folders")
Set MyFolder2 = MyFolder1.Folders("All Public Folders")
Set MyFolder3 = MyFolder2.Folders("MyPublicFolder")

Set objAllContacts = MyFolder3.Items

Dim TotalCount, Counter As Long
TotalCount = MyFolder3.Items.Count

Counter = 1
Dim ContactArray As Variant


For Each Contact In objAllContacts

ReDim ContactArray(Counter, 1) As Variant

MyAddress= Contact.BusinessAddressStreet + ", " +
Contact.BusinessAddressPostalCode + " " + Contact.BusinessAddressCity
ContactArray(Counter, 0) = Contact.CompanyName
ContactArray(Counter, 1) = MyAddress

Counter = Counter + 1
Next Contact

CForm.MyListBox.ColumnCount = 2
CForm.MyListBox.List = ContactArray

End Function

Thanx in advance
Greetings Depez
 
K

Ken Johnson

Hi,

Your problem is probably the way you are using ReDim Preserve.

Refer to the VB Help file "ReDim Statement" where it states...

If you use the Preserve keyword, you can resize only the last array
dimension and you can't change the number of dimensions at all. For
example, if your array has only one dimension, you can resize that
dimension because it is the last and only dimension. However, if your
array has two or more dimensions, you can change the size of only the
last dimension and still preserve the contents of the array.

Ken Johnson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top