Hi I am trying to select a set of fields from a record set and read the data into an array.
First off this is to be used with several table recoredsets all having the same naming structure but different qty of fields. Eg
Table 1 has fields named "Number_1,Number_2,Number_3
Table 2 has fields named Number_1,Number_2,Number_3,Number_4,Number_5
Table 3 has fields named Number_1,Number_2,Number_3,Number_4
The number of fields to read is an unknown qty until run time
At run time the data table gives me the total number of numbers in the table.
I have created a recordset of the table and an array to hold the data I have created a string to hold the field name and a for next loop to increment the trailing number but I keep getting an error message telling me item not found in record set. Is it possible to step through the field names in this manner?
I would appreciate any help on this matter.
this is a sample of the code
dim db as databace
dim Rst as recordset
dim ArrayNum()
dim x as integer
dim NumInSet
dim SrtFieldName as string
Set db = CurrentDb
Set Rst= db.OpenRecordset("tblNumData", dbOpenSnapshot)
with rst
.movelast
NumInSet = !totalNumbers
redim ArrayNum(1,NumInSet)
SrtFieldName = "!Number_" & x
for x = 1 to NumInSet
SrtFieldName = "!Number_" & x
ArrayNum(1,X) = SrtFieldName
next x
First off this is to be used with several table recoredsets all having the same naming structure but different qty of fields. Eg
Table 1 has fields named "Number_1,Number_2,Number_3
Table 2 has fields named Number_1,Number_2,Number_3,Number_4,Number_5
Table 3 has fields named Number_1,Number_2,Number_3,Number_4
The number of fields to read is an unknown qty until run time
At run time the data table gives me the total number of numbers in the table.
I have created a recordset of the table and an array to hold the data I have created a string to hold the field name and a for next loop to increment the trailing number but I keep getting an error message telling me item not found in record set. Is it possible to step through the field names in this manner?
I would appreciate any help on this matter.
this is a sample of the code
dim db as databace
dim Rst as recordset
dim ArrayNum()
dim x as integer
dim NumInSet
dim SrtFieldName as string
Set db = CurrentDb
Set Rst= db.OpenRecordset("tblNumData", dbOpenSnapshot)
with rst
.movelast
NumInSet = !totalNumbers
redim ArrayNum(1,NumInSet)
SrtFieldName = "!Number_" & x
for x = 1 to NumInSet
SrtFieldName = "!Number_" & x
ArrayNum(1,X) = SrtFieldName
next x