Populate a Dynamic Array

E

Eddy

I am trying to populate an array with a value from each control in a report
section. Specfically the 'Top' value of the control. I am using the
following code but each element in the array is empty. First time using
arrays, Help. Thanks.

ReDim varValue(intX + 34)
For Each ctl In Me.GroupHeader3.Controls
varValue(intX) = ctl.Top
' intX = intX + 1
Next ctl
 
D

Douglas J. Steele

If your array already has data in it and you're redimensioning it, you need
to include the Preserve key word to keep your existing data:

ReDim Preserve varValue(intX + 34)
 
E

Eddy

Thanks for the response. Using Access2003 when I put the word Preserve in
as suggested I receive a error telling me "Variable Not defined" I am using
the following line of code: ReDim Preserve varValue(intX + 34)
Without the word Preserve the code does not generate the error.
 
D

Douglas J. Steele

In order to use ReDim, you must Dim the variable first without a size:

Dim varValue()
....
ReDim Preserve varValue(intX + 34)
 

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