BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Filter problem.

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Desktop)
View previous topic :: View next topic  
Author Message
Steve Warburton
Guest





PostPosted: Thu Nov 18, 2004 12:06 pm    Post subject: Filter problem. Reply with quote



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





PostPosted: Thu Nov 18, 2004 2:07 pm    Post subject: Re: Filter problem. Reply with quote



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





PostPosted: Thu Nov 18, 2004 2:40 pm    Post subject: Re: Filter problem. Reply with 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
Steve Warburton
Guest





PostPosted: Thu Nov 18, 2004 2:54 pm    Post subject: Re: Filter problem. Reply with quote

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





PostPosted: Thu Nov 18, 2004 6:49 pm    Post subject: Re: Filter problem. Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Desktop) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.