Re: Buttons to change SQL in ADOQuery



Graham wrote:
I would like to be able to click on a set of small buttons captioned A, B, C etc, to change the SQL statement of an ADOQuery. in Delphi 6. The SQL refers to an Access table called HomeAd, and the buttons should filter out records where the Surname field begins with A,B,C etc.
This shows what I have done:

procedure TfmHomeAddMain.btnAClick(Sender: TObject);
begin
with HomeQuery do
begin
Close;
SQL.Clear;
SQL.Add('SELECT * FROM HomeAd');
if Sender = btnA then
SQL.Append('WHERE Surname LIKE''A%''');
Open;
end;
end;

Assuming the Button caption is only a single letter, this should work.

procedure TfmHomeAddMain.btnAClick(Sender: TObject);
var TempString: string;
begin
with Sender as TButton do TempString:=Caption;

with HomeQuery do
Close;
SQL.Clear;
SQL.Add('SELECT * FROM HomeAd WHERE Surname LIKE''TempString%''');
Open;
end;
end;

--
Jon Purvis
Texas Parks and Wildlife Department
Austin, TX
.