GetRows to Array

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
1,958
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I have opened a recordset to 2 fields in my table and applied GetRows.

The result is

Image5.jpg


How could I best get field 1 into a 1 dimensional array and field 2 into another 1 dimensional array ?
The reason is to Filter them and that needs a 1 dimensional array.
 
>You're in a database - why use filter on an array? Use "WHERE" with a query!
I wanted 2 fields from the table, each copied to their own array.
Afaik Getrows in the only way to get a recordset into an array. But you get an array that's no good and whatever approach results in a bottle neck of some kind.

Here's my 2 to 1 deminsion stuff. maybe it can be improved on ?
Code:
Function TwotoOneDimension(a3)
Dim i%, OneD As Variant
ReDim OneD(UBound(a3, 2))
For i = 0 To UBound(a3, 2)
    OneD(i) = a3(0, i)
Next
TwotoOneDimension = OneD
End Function
When I use Getrows in Access, I don't get those extra argument options showing

Image6.jpg
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Just because Intellisense doesn't list it doesn't mean it's not there.

What version of ADO are you using anyway?

Also, why do you want 2 separate arrays from the same table?
 
Upvote 0
AlexanderBB is probably using the DAO GetRows() method, not the ADO GetRows() method.


This function looks fine to me. Performance should be good, since it's a single pass through the records:
Code:
Function TwotoOneDimension(a3)
Dim i%, OneD As Variant
ReDim OneD(UBound(a3, 2))
For i = 0 To UBound(a3, 2)
    OneD(i) = a3(0, i)
Next
TwotoOneDimension = OneD
End Function



>You're in a database - why use filter on an array? Use "WHERE" with a query!
I wanted 2 fields from the table, each copied to their own array.
Afaik Getrows in the only way to get a recordset into an array. But you get an array that's no good and whatever approach results in a bottle neck of some kind.
Note, here I was more imagining not using arrays at all - recordsets can do filtering too. However, arrays are enjoyable to work with for their simplicity and efficiency, so no problem if you find them preferable in this situation.
 
Last edited:
Upvote 0
> Also, why do you want 2 separate arrays from the same table?

Been thinking how best to answer that (without going into a complex and boring design speal...) but I can't !
Yes, I am using the native Getrows from Access 2007.

Thanks for the replies, I think I'm there now, with as good a method as there is :)

Rgds, ABB
 
Upvote 0

Forum statistics

Threads
1,221,889
Messages
6,162,624
Members
451,778
Latest member
ragananthony7911

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top