Access Query Recordet conversion to an Array
Team,
I have a problem with converting a recordset to an array. I am using the
following code to get the array together but my problem is defining the
array dimensions.
I am oversizing the array to contain the data but i need to have exact
sizes. My seond problem is when you bring a recordset in that has various
datatypes how can you get an array to handle the various data types or am i
missing the point with the migration from queries to excel.
My form for this particular problem is to bring in operational data from a
access database and complete vba routines on the data to quickly crunch the
outputs, produce charts, summary diagrams etc.
Thanks if possible in advance
Shane
Set cn = New ADODB.Connection
cn.ConnectionString = Cs
cn.Open
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = cn
cmd.CommandText = Query
cmd.CommandType = adCmdText
Set rs = New ADODB.Recordset
Set rs.Source = cmd
rs.Open
Dim i As Long
Dim j As Long
Dim Data(10000, 100) As Integer
Cells.Select
Selection.ClearContents
i = 1
Do While Not rs.EOF
j = 1
For Each f In rs.Fields
Data(i, j) = f.Value
Cells(i, j) = Data(i, j)
Debug.Print Data(i, j)
j = j + 1
Next f
rs.MoveNext
i = i + 1
Loop
|