Forum Discussion
rhill1959
Apr 26, 2023Copper Contributor
Dynamic reference to array
Hi, it's been a long time since I've done any VBA code within Access. I have a situation where I globally defined 2 arrays. Dim a1() as string Dim a2() as string Within a Sub routine, I need to c...
rhill1959
Apr 26, 2023Copper Contributor
Thanks Tom,
I actually did that as a work around, but was hoping to figure out a way to reference the array name through a variable value.
Tom_van_Stiphout
Apr 26, 2023Iron Contributor
Maybe you can pass the array to work on as an argument?
- rhill1959Apr 26, 2023Copper Contributor
Thanks, that was what I needed. Here's what worked for me.
'Global Setting
Dim a1() as string
Sub call_testArray()
testArray a1
for x =1 to ubound(a1)
debug.print a1(x) 'should print "Add array Value"
next x
Sub testArray(ByRef arrayName)
redim preserve arrayName(1)
arrayName(1) = "Add array Value"
- Tom_van_StiphoutApr 26, 2023Iron ContributorNote that unless you change the default with OPTION BASE, array indexes start at 0.