How could this be optimized for speed by batching or other techniques? Its a 20MB Access2003 Database I am searching from Excel 2003 VBA.
I have my Access Table Keyed (autonumber) so I though this would provide intelligent non-linear searching like binary searches. Currently searching for 4000 values from a table of 147k records is taking 4.2 minutes.
I found this in a search:
The problem with a straight SELECT on the SQL Server side is that the DB will do a linear search through the table unless the column you're working with has an index on it; then the DB can be smarter.StackOverflow SQL C# Binary Search Question
Is this true and does it also apply to Access2003 DB?
VBA Code, Example:
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection 'open the connection
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open "PNdb2003.mdb"
End With
'define the record set
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient 'for smaller datasets that fit into RAM
For Each myVariant In Selection.Cells
strSearchText = myVariant
Dim sSQL As String
sSQL = "SELECT Key FROM [MasterTable] WHERE PN=""" & strSearchText & """"
rst.Open Source:=sSQL, ActiveConnection:=cnn, CursorType:=adOpenStatic, LockType:=adLockOptimistic
Cells(myVariant.Row, 7).CopyFromRecordset rst
rst.Close
Next myVariant
cnn.Close