H
Hugh Welford
Hi
I am trying to populate a dynamic array using redim at function level with
the code
Set theset = thedb.OpenRecordset("medications")
Call populatetablearray(theset.RecordCount)
Function populatetablearray(tablecount)
Dim thedb As Database
Set thedb = CurrentDb()
Dim theset2 As Recordset
Set theset2 = thedb.OpenRecordset("medications")
ReDim tablearray(tablecount )
For I = 1 To tablecount
tablearray(I) = theset2(0)
Debug.Print tablearray(I)
theset2.MoveNext
Next I
End Function
The debug print shows the array being populated as i expect, and a
?tablearray(6) within the intermediate window shows the correct entry, but
as soon as I exit from the function aceessing the array e.g. ?tablearray(6)
from within the intermediate window gives a "error 9 subscript out of range"
error message.
Can any one tell me what is wrong and what I should do to correct it.
Thanks Hugh
I am trying to populate a dynamic array using redim at function level with
the code
Set theset = thedb.OpenRecordset("medications")
Call populatetablearray(theset.RecordCount)
Function populatetablearray(tablecount)
Dim thedb As Database
Set thedb = CurrentDb()
Dim theset2 As Recordset
Set theset2 = thedb.OpenRecordset("medications")
ReDim tablearray(tablecount )
For I = 1 To tablecount
tablearray(I) = theset2(0)
Debug.Print tablearray(I)
theset2.MoveNext
Next I
End Function
The debug print shows the array being populated as i expect, and a
?tablearray(6) within the intermediate window shows the correct entry, but
as soon as I exit from the function aceessing the array e.g. ?tablearray(6)
from within the intermediate window gives a "error 9 subscript out of range"
error message.
Can any one tell me what is wrong and what I should do to correct it.
Thanks Hugh