iain macgranthin said:
Thanks:
I am actually keeping the rst2 recordset open while
looping through the recordset (rst1) that contains values
for the seek: the seek is used about 600 times at the
moment, and a new record added to rst2 recordset when
nomatch is true.
yes, note that I was stating that using sql each time would NOT be so bad IF
YOU could keep the rocordset open. (but you can't, ....because each time you
are stuffing a new sql statement and a new recordset gets created). As
mentioned, it is all the time to "connect" to the table, and setup the
reocrdset that is the largest performance hit.
At first I tried Findfirst, but access told me this method
was invalid for the recordset. So I moved on to seek.
FindFirst should work, (and, it works on linked tables). FindFist needs a
full "where" clause like sql.
strWhere = "City = 'Edmonton' and Country = 'Canada'"
rstRec.FindFirst (strWhere)
if rstRec.FindFirst.NoMatch = true then
msgbox "not found"
else
msgobox "found one"
endif
So, the advantage of findfirst is that the recordset stays open (I can't
stress how costly the opening is in terms of performance). The disadvantage
is that findfirst DOES NOT take advantage of indexing! So, findfirst don't
use the indexing well at all. If findfirst/findnext used indexing, this
would be no brain answer (I would say dump seek, and using
findfirst/findnext..but it don't use indexing!). In fact, if your table is
less then 3,000 records, then findfirst would be ok. If the table is larger,
then again too much scanning of the table will occur and slow things down.
So, the ideal is using some sql statement to ONLY return the needed records
(but, this may not be possible...and thus your need to "loop".
However, if it is a legacy method what should I be using?
As I am looping, I dont really want to run an sql query to
create a new result set every time - even though it may be
only 600 occurrences, its not so elegant (I also have a
background in mainframe batch processes, where overheads
can accumulate, so you go for the most efficient method as
a habit)...
Yes, I can't agree more with the above. So, if the table is to be small
(less then 2000 records, then findfirst/findnext is ok). For larger data
sets, you either have to come up with some kind of sql statement here
(perhaps a join statement to return matches between the two tables that
match...that BY FAR the fast way).
If you can't use a sql join to match/compare values between the two tables,
then you are stuck (that in my humbale opiion is the real soltion here). You
will have to make the comprise to use findfirst. Or, if you must, continue
to use the seek command. However, eventually, you will want to split your
mdb. You can use the following workaround to use the seek command in linked
tables. So, if no way to use sql for the matching, then I would continue to
use the seek.
All the below link says is that you can open the linked mdb file by a full
path name, and then still use seek. Note if you have not split you mdb
file...it does not apply!)
http://www.mvps.org/access/tables/tbl0006.htm