Need Advice on how to optimize search for records in a table

SKV

Active Member
Joined
Jan 7, 2009
Messages
257
I have a table with 60k+ records. I have a VBA code for some function that search for records in this table so I use a WHILE LOOP. The problem is that this goes through each record of 60k+ rcds. So I was wondering if there is a way that search only go to specific (based on key field) records in the table.

Example: In the table below key field is (Field 1 + Field 2) i.e. Field 1 = X & Field 2 = A; there only 3 records with sequence nbrs 1, 5, 8.

Question: How can I make my code to jump directly to these rcds. The While loop or For loop goes and check each record for key thus takes a lot of time.


SeqField 1Field 2Val1
1XA23
2Y1
3FR
4FR
5XA34
6GH
7Y1
8XA65

<colgroup><col width="64" span="4" style="width:48pt"> </colgroup><tbody>
</tbody>


Please advise.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
it is not clear what you are searching for


are you searching for data in the last column?

or, do you already know the record numbers that you want to retrieve?

you can cut the search down by exiting the search routine once the record is found

also you can use adodb to retrieve the data
 
Upvote 0
If you have created a compound index on field1 + field2, Access knows that.
When you create a query, part of the query optimizer within the database will identify whether indexes exist and if they should participate in your query. If the index is relevant it will be used.
So
Code:
SELECT * 
FROM myTable
WHERE
field1 & field2 = "XA"

will return records 1,5,8 and it will use your index
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,543
Messages
6,125,423
Members
449,223
Latest member
Narrian

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