View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jamie Collins Jamie Collins is offline
external usenet poster
 
Posts: 593
Default comparing distinct data

AA2e72E, A few points:

1) Your code uses ADO to query an open workbook. This is a bad idea due
to an ADO bug:

BUG: Memory leak occurs when you query an open Excel worksheet by using
ActiveX Data Objects (ADO)

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

2) The Microsoft OLE DB provider for Jet 4.0 is the provider of choice
for ADO enthusiast in this group, so your connection string could be
re-written as:

Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=C:\Tempo\db.xls;
Extended Properties=Excel 8.0

Perhaps you were using the odbc driver and respective provider in an
attempt to circumvent the memory leak bug? This does not work because
the bug is in ADO and is not limited to particular drivers and
providers. I've tested with the OLE DB providers for Jet 4.0, Jet 3.51
and odbc and all caused the memory leak to occur. The only realistic
work around is to use a closed copy of the workbook and, contrary to
Method 1 in the above MS article, the copy should not be made using
SELECT..INTO because this in itself involves querying the open
workbook.

3) The usual approach is to JOIN the sheets/tables. Here's is a
suggested alternative using a JOIN:

SELECT T2.*
FROM [Sheet2$] AS T2
INNER JOIN [Sheet1$] AS T1
ON T2.ID = T1.ID;

FWIW your subquery construct should be equivalent in terms of
performance; in fact, my experience of Jet suggests yours may even run
a little faster than mine. I post mine merely because it is the more
common construct.

4) The data/header row does not need to start in row 1 when using
[Sheet1$] as the table name. Jet will determine the table confines
using the UsedRange (but at a much lower level than VBA does).

Jamie.

--