The initial declaration must be made without dimensions. You use 'Preserve' to enlarge a dynamic array which has already been dimensioned once dynamically, if you want to keep the values already entered.
(°v°)
Main Topics
Browse All TopicsI have the following:
ReDim Preserve jobCodes(0 To jbMax) As String
and when I compile I get the compile error: Array Already Dimensioned
The message is true: my array *was* previously dimensioned. This is my frist shot at using dynamic arrays, so I'm sure I'm doing something wrong, but I thought one was supposed to use the "Preserve" when the arrary was previously dimensioned. What am I doing wrong?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The Preserve keyword is used when you want to "Preserve" the values already assigned to your Array elements and only works if you are increasing the elements.
You do not need to DIM an array, the ReDim does the job for you.
The following example will print A to F in the Immediate window, if you take out the PRESERVE then you will get 5 blank lines followed by E and F.
Are you changing the defined type, say to string from variant?
Finally, what version of Access are you using my tests were in Access 2007 but I am fairly sure the previous versions were the same.
Cheers, Andrew
> You do not need to DIM an array
That is true. Option Explicit will not catch the problem. Formally (from the VB help file), you should not use it that way:
The ReDim statement is used to size or resize a dynamic array that has already been formally declared using a Private, Public, or Dim statement with empty parentheses (without dimension subscripts).
The problem becomes apparent in the snippet. The typo isn't identified, and the code breaks only at run-time. I don't know why the VB compiler was made to imply Dim when reading ReDim, these are quite different operations, and no other language makes that particular confusion. Anyway, you are right:
ReDim Something(12) As String
Is interpreted as
Dim Something() As String
ReDim Something(12)
Stupid, but there you go...
(°v°)
Business Accounts
Answer for Membership
by: LSMConsultingPosted on 2009-02-24 at 11:00:20ID: 23724974
How was your array dimensioned originally? Was it also an array of Strings?