Agregate function/MSJET40.DLL/AV

Hi everybody,

  When I run my application from within the Delphi IDE calling any SQL
agregate functions result in an AccessViolation when the line containing
the functionl (SUM()) is read.

The error Message is "Project p.exe raised exception Class
EAccessViolation at address..... in module MSJET40.DLL ....Process
stopped....."

When running the application from outside the IDE no AV occurs. After
the AV occurs the rest of the function execute correctly and the result
is good. When the Open method is called, no error occurs, the error
occurs only when reading the line containing the agregate function. Is
it a known problem? How to avoid this AV?

function TFrmMain.InStock(PartNo, RevNo: String): Double;
var
  InvQuery: TADOQuery;
begin
  try
    InvQuery := TADOQuery.Create(Application);
    InvQuery.Connection := DMod.ADOConnection;

    with InvQuery do
    begin
      Close;
      with SQL do
      begin
        Clear;
        Add('SELECT SUM(QTY)');    //******* the AV occurs here
***********
        Add('FROM INVENTORY');
        Add('WHERE PART_NO = :PART_NO AND REV_NO = :REV_NO');
        Parameters[0].Value := PartNo;
        Parameters[1].Value := RevNo;
      end;
      Open;

      if RecordSet.RecordCount > 0 then
      begin
        if Fields[0].Value = Null then
          Result := 0
        else
          Result := Fields[0].Value;

      end;
    end;
  finally
    InvQuery.Close;
    InvQuery.Free;

  end;

end;

Thank you all
Serge Myrand