Go Back   Access World Forums > Microsoft Access Reference > Access FAQs

Closed Thread
Thread Tools Rate Thread Display Modes
Old 06-20-2010, 04:57 PM   #1
Join Date: Jun 2007
Location: Universe - Local Group - Milky Way Galaxy - Orion Arm
Posts: 5,640
Thanks: 0
Thanked 100 Times in 47 Posts
ajetrumpet has a spectacular aura about ajetrumpet has a spectacular aura about
Send a message via MSN to ajetrumpet Send a message via Yahoo to ajetrumpet
VBA Create Array

Static / Fixed Arrays

These are manually dimensionalized. Dimensions and number of elements are defined manually when arrays are declared. Short example:

    Dim myarray(6) As Variant
These have to be populated from their declaration specs. For example:

dim i as long

   for i = 0 to 5
      myarray(i) = i
   next i
Dynamic Arrays

These are unspecified in terms of dimensions and number of elements. Example:

    Dim myarray() As Variant
These have to be redimensionalized everytime an element or a dimension is added. The ReDim statement is used for this. Using ReDim alone will empty the area everytime it is redimensionalized so you have to populate it afterwards. Use this on arrays with more than one dimension. Example:

dim i as long
dim j as long

   for i = 0 to 5
      for j = 0 to 10
         ReDim(i, j)
      next j
   next i
Using ReDim Preserve saves the values that are already in the array and also redimensionalizes it. It saves time for one-dimensionals, like:

dim i as long

   for i = 0 to 5
      ReDim Preserve myarray(i)
      myarray(i) = i
   next i
More than one dimension usually does not work with Preserve because the last dimension must not be manipulated when using the key word.

ajetrumpet is offline  
The Following 2 Users Say Thank You to ajetrumpet For This Useful Post:
hassanogaibi (06-28-2016), Tango (07-19-2012)
Closed Thread

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a SQL statement in VBA xzmilan Modules & VBA 7 03-12-2010 07:09 AM
Create a new .mdb with vba Somebody General 1 07-07-2008 09:17 AM
A control array in VBA like in VB6 is that possible? Guus2005 Modules & VBA 4 06-13-2008 05:16 AM
[Access 2007] How do i create table in VBA dibangdit Modules & VBA 2 05-21-2008 08:32 PM
Formatting Error with VBA Array? M_S_Jones Modules & VBA 3 03-07-2008 05:55 AM

All times are GMT -8. The time now is 02:50 PM.

Microsoft Access Help
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post

Sponsored Links

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World