Board index » delphi » partial filtering?

partial filtering?

Hi Everyone,

I'm having a little difficulty  searching through a database trying to
find a partial match on a date field.  (Delphi 3) Let me explain:

I need to print a report showing monthly  birthdays. I'm trying to
filter tbe database. So far  I've tried using the filter in the object
inspector....now I'm on to the onFilterRecord method.....trying to use
the decodeDate() method to break the date down into month, day and year
( hoping to match it with the month choosen from a comboBox)  but
despite the fact that the field in the database is a date field it
doesn't seem to work!
Can someone suggest a plan of attack?

Thanks,
Dan
dan_...@istar.ca

 

Re:partial filtering?


On Fri, 12 Feb 1999 11:16:19 -0400, Dan Grantham <dan_...@istar.ca>
wrote:

Quote
>Hi Everyone,

>I'm having a little difficulty  searching through a database trying to
>find a partial match on a date field.  (Delphi 3) Let me explain:

>I need to print a report showing monthly  birthdays. I'm trying to
>filter tbe database. So far  I've tried using the filter in the object
>inspector....now I'm on to the onFilterRecord method.....trying to use
>the decodeDate() method to break the date down into month, day and year
>( hoping to match it with the month choosen from a comboBox)  but
>despite the fact that the field in the database is a date field it
>doesn't seem to work!
>Can someone suggest a plan of attack?

On the other hand what I previously posted works only if all the dates
you are looking for have the same year on the db.  I'm now suspecting
this might not be your case.

Tell us something more...

Regards,

--
Marco Rocci
MicroEra srl
Turin, Italy

Re:partial filtering?


On Fri, 12 Feb 1999 11:16:19 -0400, Dan Grantham <dan_...@istar.ca>
wrote:

Quote
>Hi Everyone,

>I'm having a little difficulty  searching through a database trying to
>find a partial match on a date field.  (Delphi 3) Let me explain:

>I need to print a report showing monthly  birthdays. I'm trying to
>filter tbe database. So far  I've tried using the filter in the object
>inspector....now I'm on to the onFilterRecord method.....trying to use
>the decodeDate() method to break the date down into month, day and year
>( hoping to match it with the month choosen from a comboBox)  but
>despite the fact that the field in the database is a date field it
>doesn't seem to work!
>Can someone suggest a plan of attack?

I would use a TQuery with a BETWEEN condition

   SELECT * FROM BirthDates
   WHERE BithDate BETWEEN :BegOfMonth AND :EndOfMonth

Then use the TComboBox.OnChange or OnExit event-handler to:

 * close the query
 * set the two parameters
 * reopen the query

You can easily use the EncodeDate function to build the two dates.

Regards,

--
Marco Rocci
MicroEra srl
Turin, Italy

Re:partial filtering?


What doesn't work, the decode date or the onFilterRecord? If the filter
procedure isn't too long, perhaps you could post it.
Quote
Dan Grantham wrote in message <36C445C3.D99EE...@istar.ca>...
>Hi Everyone,

>I'm having a little difficulty  searching through a database trying to
>find a partial match on a date field.  (Delphi 3) Let me explain:

>I need to print a report showing monthly  birthdays. I'm trying to
>filter tbe database. So far  I've tried using the filter in the object
>inspector....now I'm on to the onFilterRecord method.....trying to use
>the decodeDate() method to break the date down into month, day and year
>( hoping to match it with the month choosen from a comboBox)  but
>despite the fact that the field in the database is a date field it
>doesn't seem to work!
>Can someone suggest a plan of attack?

>Thanks,
>Dan
>dan_...@istar.ca

Re:partial filtering?


Dan,

Have you tried this...?

procedure TForm1.ComboBox1Click(Sender: TObject);
begin
  Table1.Filtered := True;
end;

procedure TForm1.Table1FilterRecord(DataSet: TDataSet; var Accept:
Boolean);
var
  Year, Month, Day: Word;
begin
  DecodeDate(Table1BirthdayDate.AsDateTime, Year, Month, Day);
  Accept := Month = ComboBox1.ItemIndex + 1;
end;

...where ComboBox1 lists the months in order.

--
Stephen Brown

Quote
Marco Rocci wrote in message

<36c64ffb.26856...@tor-nn1-ca.netcom.ca>...
Quote
>On Fri, 12 Feb 1999 11:16:19 -0400, Dan Grantham <dan_...@istar.ca>
>wrote:

>>I need to print a report showing monthly  birthdays. I'm trying to
>>filter tbe database. So far  I've tried using the filter in the
object
>>inspector....now I'm on to the onFilterRecord method.....trying to
use
>>the decodeDate() method to break the date down into month, day and
year
>>( hoping to match it with the month choosen from a comboBox)  but
>>despite the fact that the field in the database is a date field it
>>doesn't seem to work!

Re:partial filtering?


I am having the exact problem, I have tried the recommendation below but
I don't seems to be able to get it to work. I have error on the
AsDateTime part.

Regards,

Elvin Tan

Quote
Stephen Brown wrote:
> Dan,

> Have you tried this...?

> procedure TForm1.ComboBox1Click(Sender: TObject);
> begin
>   Table1.Filtered := True;
> end;

> procedure TForm1.Table1FilterRecord(DataSet: TDataSet; var Accept:
> Boolean);
> var
>   Year, Month, Day: Word;
> begin
>   DecodeDate(Table1BirthdayDate.AsDateTime, Year, Month, Day);
>   Accept := Month = ComboBox1.ItemIndex + 1;
> end;

> ...where ComboBox1 lists the months in order.

> -

--
Email address is spams protected, delete "remove_" to email.

Re:partial filtering?


Quote
Elvin Tan wrote in message <36C6A6C9.C7C73...@post1.com>...
>I am having the exact problem, I have tried the recommendation below
but
>I don't seems to be able to get it to work. I have error on the
>AsDateTime part.

Elvin,

What sort of error? If AsDateTime is causing it, then it sounds as if
the field you are referencing in the filter expression is not a proper
date type field. Check the table structure or the TField object to see
what type it is.

If you are storing dates in a string field (not a good idea), then you
will have to use the StrToDate function.

Stephen Brown

Quote
>> procedure TForm1.ComboBox1Click(Sender: TObject);
>> begin
>>   Table1.Filtered := True;
>> end;

>> procedure TForm1.Table1FilterRecord(DataSet: TDataSet; var Accept:
>> Boolean);
>> var
>>   Year, Month, Day: Word;
>> begin
>>   DecodeDate(Table1BirthdayDate.AsDateTime, Year, Month, Day);
>>   Accept := Month = ComboBox1.ItemIndex + 1;
>> end;

>> ...where ComboBox1 lists the months in order.

Re:partial filtering?


Hi

Maybe it's just a stupid remark at this point but.... I had a problem
similar to these and i found that it was a miscommunication between the BDE
and Delphi/windows....  The BDE used a different data setting MM/DD/YYYY
then my puter DD/MM/YYYY.... so that was causing probs...

L8R

Arjen
http://www.dgdr.com

Quote
Stephen Brown wrote in message <7a7uke$2q...@plutonium.compulink.co.uk>...
>Elvin Tan wrote in message <36C6A6C9.C7C73...@post1.com>...
>>I am having the exact problem, I have tried the recommendation below
>but
>>I don't seems to be able to get it to work. I have error on the
>>AsDateTime part.

>Elvin,

>What sort of error? If AsDateTime is causing it, then it sounds as if
>the field you are referencing in the filter expression is not a proper
>date type field. Check the table structure or the TField object to see
>what type it is.

>If you are storing dates in a string field (not a good idea), then you
>will have to use the StrToDate function.

>Stephen Brown

>>> procedure TForm1.ComboBox1Click(Sender: TObject);
>>> begin
>>>   Table1.Filtered := True;
>>> end;

>>> procedure TForm1.Table1FilterRecord(DataSet: TDataSet; var Accept:
>>> Boolean);
>>> var
>>>   Year, Month, Day: Word;
>>> begin
>>>   DecodeDate(Table1BirthdayDate.AsDateTime, Year, Month, Day);
>>>   Accept := Month = ComboBox1.ItemIndex + 1;
>>> end;

>>> ...where ComboBox1 lists the months in order.

Other Threads