| View previous topic :: View next topic |
| Author |
Message |
Steve Warburton Guest
|
Posted: Thu Nov 18, 2004 12:06 pm Post subject: Filter problem. |
|
|
I have the following code on 3 radiobuttons.
procedure TForm1.RadioButton13Click(Sender: TObject);
begin
// bring back all data;
Datamodule2.Table_Invoice_Reports.Close;
Datamodule2.Table_Invoice_Reports.open;
Datamodule2.Table_Invoice_Reports.Filtered := false;
end;
procedure TForm1.RadioButton14Click(Sender: TObject);
begin
// bring back all paid data;
Datamodule2.Table_Invoice_Reports.Close;
Datamodule2.Table_Invoice_Reports.open;
Datamodule2.Table_Invoice_Reports.Filter := 'Pay_Date <>
NULL';
Datamodule2.Table_Invoice_Reports.Filtered := true;
end;
procedure TForm1.RadioButton16Click(Sender: TObject);
begin
// bring back unpaid data;
Datamodule2.Table_Invoice_Reports.Close;
Datamodule2.Table_Invoice_Reports.open;
Datamodule2.Table_Invoice_Reports.Filter := 'Pay_Date =
Null';
Datamodule2.Table_Invoice_Reports.Filtered := true;
end;
These work fine and filter the table correctly.
When I add another radio button with the following code:
procedure TForm1.RadioButton31Click(Sender: TObject);
begin
// bring back data payed by cheque;
Datamodule2.Table_Invoice_Reports.Close;
Datamodule2.Table_Invoice_Reports.open;
Datamodule2.Table_Invoice_Reports.Filter := 'Pay_Type =
Cheque';
Datamodule2.Table_Invoice_Reports.Filtered := true;
end;
I get the error Field Cheque does not exist.
What am I doing wrong. The Field Pay_Type does exist in the table.
Cheers
SteveW
|
|
| Back to top |
|
 |
Bill Todd Guest
|
Posted: Thu Nov 18, 2004 2:07 pm Post subject: Re: Filter problem. |
|
|
Datamodule2.Table_Invoice_Reports.Filter := 'Pay_Type = ' +
QuotedStr('Cheque');
--
Bill (TeamB)
TeamB cannot answer questions received via email
Steve Warburton wrote:
| Quote: | Datamodule2.Table_Invoice_Reports.Filter := 'Pay_Type =
Cheque';
|
|
|
| Back to top |
|
 |
Dell Stinnett Guest
|
Posted: Thu Nov 18, 2004 2:40 pm Post subject: Re: Filter problem. |
|
|
Try this:
Datamodule2.Table_Invoice_Reports.Filter := 'Pay_Type = "Cheque"';
Also, is your Datamodule2.Table_Invoice_Reports a Table or a Query? If
it's a table, you don't have to do .Close and .Open, all you need is
..Refresh. If it's a query, I would set the filter between the close and
open - filters on queries set the Where clause in the SQL, so it's more
efficient to do it this way.
-Dell
|
|
| Back to top |
|
 |
Steve Warburton Guest
|
Posted: Thu Nov 18, 2004 2:54 pm Post subject: Re: Filter problem. |
|
|
I get the error 'Invalid filter expression Character ""
"Dell Stinnett" <dell.stinnett> wrote
| Quote: | Try this:
Datamodule2.Table_Invoice_Reports.Filter := 'Pay_Type = "Cheque"';
Also, is your Datamodule2.Table_Invoice_Reports a Table or a Query? If
it's a table, you don't have to do .Close and .Open, all you need is
.Refresh. If it's a query, I would set the filter between the close and
open - filters on queries set the Where clause in the SQL, so it's more
efficient to do it this way.
-Dell
|
|
|
| Back to top |
|
 |
Wayne Niddery [TeamB] Guest
|
Posted: Thu Nov 18, 2004 6:49 pm Post subject: Re: Filter problem. |
|
|
Steve Warburton wrote:
| Quote: |
procedure TForm1.RadioButton14Click(Sender: TObject);
begin
// bring back all paid data;
Datamodule2.Table_Invoice_Reports.Close;
Datamodule2.Table_Invoice_Reports.open;
Datamodule2.Table_Invoice_Reports.Filter := 'Pay_Date
NULL';
Datamodule2.Table_Invoice_Reports.Filtered := true;
|
Two things. 1. You should never compare to NULL. Null is not a value. If
youuse this against an SQL databsae, you will get zero results. You should
change this to 'Pay_Date IS NOT NULL'. 2. You should set the flter/filtered
properties *before* opening the dataset. Again if this is an SQL database,
the filter will be turned into a Where clause making retrieval much more
efficient. Opening the table without the filter (or a wrong one) makes this
very inefficient.
| Quote: | Datamodule2.Table_Invoice_Reports.Filter := 'Pay_Date
= Null';
|
You should change this to 'Pay_Date IS NULL'.
| Quote: | When I add another radio button with the following code:
Datamodule2.Table_Invoice_Reports.Filter := 'Pay_Type
= Cheque';
I get the error Field Cheque does not exist.
|
Cheque is a string value in this case so must be quoted. Use QuotedStr.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"The moment the idea is admitted into society that property is not as
sacred as the laws of God and there is not a force of law and public
justice to protect it, anarchy and tyranny commence." - John Adams
|
|
| Back to top |
|
 |
|