Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
TK TK is offline
external usenet poster
 
Posts: 177
Default Access Query Recordet conversion to an Array

Hi Shane

Just a though for you to consider. Why not populate the
worksheet with the segregated data from a recordedset
and start your manipulation and analysis in excel.

Good Luck
TK


"Shane King" wrote:

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Access Query Recordet conversion to an Array

Thanks for the advice but i have some 600,000 rows of data to manipulate..
So this is to large to populate excel..

Thanks S
"TK" wrote in message
...
Hi Shane

Just a though for you to consider. Why not populate the
worksheet with the segregated data from a recordedset
and start your manipulation and analysis in excel.

Good Luck
TK


"Shane King" wrote:

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





  #4   Report Post  
Posted to microsoft.public.excel.programming
TK TK is offline
external usenet poster
 
Posts: 177
Default Access Query Recordet conversion to an Array

Hi Shane

Well there are numerous ways to process data.
Jamie suggested a couple and here is yet another.
Build the (selection, action or whatever)
Query in Access. Then call the Query from Excel
for presentation.

Good Luck
TK

"Shane King" wrote:

Thanks for the advice but i have some 600,000 rows of data to manipulate..
So this is to large to populate excel..

Thanks S
"TK" wrote in message
...
Hi Shane

Just a though for you to consider. Why not populate the
worksheet with the segregated data from a recordedset
and start your manipulation and analysis in excel.

Good Luck
TK


"Shane King" wrote:

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






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default Access Query Recordet conversion to an Array

"Shane King" wrote in message ...

i have some 600,000 rows of data to manipulate..
to this is to large to populate excel


Can you do any manipulation using SQL to reduce the number of rows
selected? 600K rows is a lot to work with in memory.

Jamie.

--


  #6   Report Post  
Posted to microsoft.public.excel.programming
TK TK is offline
external usenet poster
 
Posts: 177
Default Access Query Recordet conversion to an Array

Hi Jamie:
Always nice to here from you.

€œCan you do any manipulation using SQL to reduce the number of rows€

Well a couple ideas come to mind i.e.
Where
Distinct
Group
Join
Having
Ordered BY
Top
Sub queries


TK

"Jamie Collins" wrote:

"Shane King" wrote in message ...

i have some 600,000 rows of data to manipulate..
to this is to large to populate excel


Can you do any manipulation using SQL to reduce the number of rows
selected? 600K rows is a lot to work with in memory.

Jamie.

--

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default Access Query Recordet conversion to an Array

"TK" wrote ...

Hi Jamie:
Always nice to here from you.

“Can you do any manipulation using SQL to reduce the number of rowsâ€Â

Well a couple ideas come to mind i.e.
Where
Distinct
Group
Join
Having
Ordered BY
Top
Sub queries


Perhaps I should have said:

The OP should review their SQL in case it is possible to reduce the
number of rows being returned to Excel. If the OP posted their SQL
code, example data and desired results, I'm sure they would get some
useful suggestions here.

Jamie.

--
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default Access Query Recordet conversion to an Array

"Shane King" wrote ...

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.


Some points you may be missing:

You can use the GetRows to return a zero-based variant array based on
the recorset, for which the dimensions will be dynamically sized for
you.
You can use Excel's Application.Transpose to manipulate the GetRows
results array into Excel's (rows,columns) format.
You can set an appropriately sized Range object's Value property to
equal the array transposed as above (Excel takes care of the base 0 to
base 1 conversion).
As an alternative to using an array, you can use Excel's
CopyFromRecordset to write the data to a Range.

For details, see:

http://support.microsoft.com/default...b;en-us;246335

BTW if you are changing values while looping through the recordset
which would prevent you from using the above approaches, you may be
achieve the same while fetching the data (i.e. rather than post
processing the data) by changing your SQL code and/or using data
shaping.

Jamie.

--
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Access Query Recordet conversion to an Array

Jamie,
Many thanks i have anumber of hints to go our try through
Thanks for your time.
Shane King
"Jamie Collins" wrote in message
om...
"Shane King" wrote ...

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.


Some points you may be missing:

You can use the GetRows to return a zero-based variant array based on
the recorset, for which the dimensions will be dynamically sized for
you.
You can use Excel's Application.Transpose to manipulate the GetRows
results array into Excel's (rows,columns) format.
You can set an appropriately sized Range object's Value property to
equal the array transposed as above (Excel takes care of the base 0 to
base 1 conversion).
As an alternative to using an array, you can use Excel's
CopyFromRecordset to write the data to a Range.

For details, see:

http://support.microsoft.com/default...b;en-us;246335

BTW if you are changing values while looping through the recordset
which would prevent you from using the above approaches, you may be
achieve the same while fetching the data (i.e. rather than post
processing the data) by changing your SQL code and/or using data
shaping.

Jamie.

--



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query from Access into Excel cause Access to go to read only T Stephens Excel Discussion (Misc queries) 0 March 24th 09 04:17 PM
Can I use MS Query in Excel like an Append Query in Access Sam Wardill Excel Discussion (Misc queries) 0 April 11th 06 02:41 PM
Microsoft Query rejects "nz" function in Access Query Vaughan Excel Discussion (Misc queries) 0 May 4th 05 05:20 PM
File conversion query Anna Excel Discussion (Misc queries) 3 April 20th 05 02:19 PM
How to use a Access Query that as a parameter into Excel database query Karen Middleton Excel Discussion (Misc queries) 1 December 13th 04 07:54 PM


All times are GMT +1. The time now is 05:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"