BDE: "Invalid parameter" on sql open

I've got code that looks like this stipped down version:

procedure BuildIt(ID);
var
  i:longint;
begin

  sqlOuter.parambyname('afis').asstring:=ID;
  sqlOuter.prepare;
  sqlOuter.open;
  if sqlOuter.active then begin

    sqlOuter.first;
    while not sqlOuter.eof do begin
      i:=sqlOuter.fieldbyname('transact').value;
      sqlInner.parambyname('Transact').value:=i;
      sqlInner.prepare;
      sqlInner.open; {excepts here after many runs}
      if sqlInner.active then begin
        sqlInner.first;
        while not sqlInner.eof do begin
          {do stuff}
          sqlInner.next;
        end;
        sqlInner.close;
      end;
      sqlOuter.next;
    end;
    sqlOuter.close;
  end;
end;

Problem is, the code excepts on sqlInner.open with EDatabaseError with
the message Invalid parameter--but only after BuildIt has run many
times.  With static data, it dies on ID 165465 (there are about 80 IDs
before this one).  But if I *only* allow it to run on ID 165465 it
doesn't die, and if I exclude some of the earlier IDs, the except
happens *after* 165465.

So I figure the data isn't involved, that it's got something to do
with the number of times through or the amount of data generated.

Note also that before Invalid param I got Capability not supported.  I
got rid of that by removing the ORDER BY clause of the query.  Now,
after a bunch of Invalid param excepts, the excepts change to
Capability not supported again.

I tried creating the sql component manually, as well, creating it on
entering the procedure and freeing it on exit--no difference.  I have
also fiddled with the ordering the prepare and close, all to no avail.

This is BDE 3.5, Delphi 2.01 on NT4Ws with the data on a Netware 3.12
server.  NW client is the most recent.  Transact field is Integer (4
bytes) and the table type is pdox 7.

One concrete question on the use of Self.  When I created the query
obj manually I was not able to q:=tquery.create(self) because Delphi
said Self was undefined.  Ultimately I used Application.  Why was Self
undefined?  I don't see that it requires adding a unit in USES...

I'm pretty much out of ideas.  Any help?  Any obvious problems?

Thanks.

--
Frank Burleigh 812-333-7082 (h); 812-855-9170 (o); 812-855-0555 (fax)
School of Law 254, Indiana University, Bloomington, IN  47405
Internet burle...@indiana.edu or CIS 72730,1017 (rare visits)