The
ProgrammingMSAccess.COM Site
Three VBA procedures
that demonstrate basic array processing techniques.
Dim str1(2) As String
Sub DeclaringArrays()
'Assign values to array elements
str1(0) = "Rick"
str1(1) = "Dobson"
str1(2) = "8629"
'Compute string expression with array elements
MsgBox str1(0) & " " & str1(1) & "'s extension is " & _
str1(2) & ".", vbInformation, _
"Programming Microsoft Access Version 2002"
End Sub
Sub ReDeclaringArrays()
ReDim str2(1 To 3) As String
'Assign values to array elements
'scoped at the procedure level
str2(1) = "Rick"
str2(2) = "Dobson"
str2(3) = "8629"
'Compute string expression with array elements
MsgBox str2(1) & " " & str2(2) & "'s extension is " & _
str2(3) & ".", vbInformation, _
"Programming Microsoft Access Version 2002"
'Assign procedure-level array elements to
'module-level array elements
str1(0) = str2(1)
str1(1) = str2(2)
str1(2) = str2(3)
'Compute string expression with array elements
MsgBox str1(0) & " " & str1(1) & "'s extension is " & _
str1(2) & ".", vbInformation, _
"Programming Microsoft Access Version 2002"
'Preserve initial elements and add a new one
ReDim Preserve str2(1 To 4)
str2(4) = "rickd@cabinc.net"
'Compute string expression with array elements
MsgBox str2(1) & " " & str2(2) & "'s extension and " & _
"email address are: " & str2(3) & " and " & _
str2(4) & ".", vbInformation, _
"Programming Microsoft Access Version 2002"
End Sub
Sub UsingArrayFunction()
Dim varArray As Variant
'Syntax for using Array function to create a Variant
'array; notice index starts at 0
varArray = Array("Virginia", "Dobson", "9294", "Virginia@cabinc.net")
MsgBox varArray(0) & " " & varArray(1) & "'s extension and " & _
"email address are: " & varArray(2) & " and " & _
varArray(3) & ".", vbInformation, _
"Programming Microsoft Access Version 2002"
End Sub
Want to understand Microsoft Access 2000/2002/2003 so that you can program it to
do more tasks like this? Get Programming Microsoft Office Access
2003
by Rick Dobson from Microsoft Press. Learn more about the book by clicking
here.
Copyright 2003 CAB, Inc. All rights reserved. Republication or redistribution
of CAB, Inc. content, including by framing or similar means, is expressly
prohibited without the prior written consent of CAB, Inc. CAB, Inc. shall not be
liable for any errors in the content, or for any actions taken in reliance
thereon.