Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use an 'array' in VBA?

Status
Not open for further replies.

InkyRich

Technical User
Aug 2, 2006
126
GB
Hi all,
In my distant past (in good old Basic programming - shows how old I am) I recall using an array to assign a value to a variable (say x) to collect a value in a loop (like x1 first pass, x2 second pass etc.)
I am trying to do the same in VBA in an Access database within a loop. I have created a variable called BirthdateVar and in each pass through the loop I want to take the value of x and place it on the end of the variable so that I can then take that value and use it.
Can you tell me what the syntax is for this? Remembering the old Basic I have tried BirthdateVar(x) but it doesnt work.
Any suggestions please?

Hampshire UK.

A fool and his money are soon parted - so you might as well send it to me!
 
A very basic sample of an array:

Code:
Dim [blue]BirthDateVar(5)[/blue] As String
Dim i As Integer

[blue]BirthDateVar(0) = "ABC"
BirthDateVar(1) = "XYZ"
BirthDateVar(2) = "UYT"
BirthDateVar(3) = "OPR"
BirthDateVar(4) = "KLM"
BirthDateVar(5) = "WER"[/blue]

For i = LBound([blue]BirthDateVar[/blue]) To UBound([blue]BirthDateVar[/blue])
    Debug.Print "BirthDateVar with index of " & i & " has a value of " & [blue]BirthDateVar(i)[/blue]
Next i

Have fun.

---- Andy
 
Thanks chaps,
I will give it a go.
And thanks for the code.

Hampshire UK.

A fool and his money are soon parted - so you might as well send it to me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top