Cristiane C. Andrade Guest
|
Posted: Thu Jan 29, 2004 6:34 pm Post subject: Get Recordcount - Excel QueryTable |
|
|
Hello,
I'm using Excel Automation in a Delphi application. For that I use a
TOleContainer component. I create a QueryTable object through code like the
following:
ExcelQry:=
IDispatch(OleContainer1.OleObject.Application.ActiveWorkbook.ActiveSheet.Que
ryTables.Add
(ConnStr,OleContainer1.OleObject.Application.ActiveCell,SQL)) as
_QueryTable;
with ExcelQry do
begin
Name := 'SQL';
FieldNames := False;
RowNumbers := False;
FillAdjacentFormulas := False;
PreserveFormatting := True;
RefreshOnFileOpen := False;
BackgroundQuery := True;
RefreshStyle := xlInsertDeleteCells;
SavePassword := True;
SaveData := True;
AdjustColumnWidth := True;
RefreshPeriod := 0;
PreserveColumnInfo := false;
MaintainConnection:= False;
Refresh(True);
end;
I would like to know the result query's record count. A QueryTable object
has a property called Recordset. But exceptions are raised when I try
accesssing it. What follow is sample code describing what I am doing to
achieve this:
ShowMessage(IntToStr(OleContainer1.OleObject.Application.ActiveCell.QueryTab
le.Recordset.RecordCount));
By doing this I get an exception with this message : "Not a DAO RecordSet
DataSource"
Could anyone please help or shed some light on the matter ?
Thanks in advance ,
Cris
|
|