Solved

Query Question

Posted on 1998-04-25
7
146 Views
Last Modified: 2010-04-06
Need an example of a program that posts a birthday from a field to a dbgrid,  using the Before Open Event when the current date matches the birthday. year must be omitted
I don't think i can do it in the sql using "now".

jj
0
Comment
Question by:jjhj
  • 4
  • 2
7 Comments
 
LVL 1

Expert Comment

by:Edo082297
ID: 1336950
Hi
  You can get the current date using the Date function. If the date returned by this function is in the same format as the date in your date field, then you can check for a match by passing a date; just set the param type to date in the Params property of your SQL statement. Also, look up the DecodeDate function. This function can break up a (valid!) date into it's constituent parts (i.e. Year, month, day). You can use it to do any kind of string formatting you want.
  What exactly do you want to do?

Edo
0
 

Author Comment

by:jjhj
ID: 1336951
Edo,
this is what i have

procedure TForm2.SpinButton1DownClick(Sender: TObject);
begin
Calendar1.NextMonth;
end;

procedure TForm2.Calendar1Change(Sender: TObject);
begin
With Calendar1 Do
Begin
   DateStr := DateToStr(CalendarDate);
   Panel1.Caption := LongMonthNames[Month];
   Panel2.Caption := IntToStr(Year);
   Panel3.Caption:=DateStr;
end;

procedure TForm2.FormActivate(Sender: TObject);
begin
try
Calendar1.CalendarDate := StrToDate(DateStr);
except
On EconvertError Do;
end;
Calendar1.OnChange(Calendar1);
end;

When I change dates on the calendar i need to pull a 'name' field from a table that has names and birthdays,  to a DBgrid
when the birthday equals the  calendar day

Does this make sense?
jjhj
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1336952
Hi jjhj,

If I understand correctly you need to do this :

1. User selects a date.
2. When date changes ---> display all names into a grid

Why not do this :

1. You 've one table with all information (dates, names, ...)
2. You make a query OR uses a Table (filtered!) which displays the names on the certain dates (chosen by user)
3. Grid has datasource attached to Query or Table.

correctly?

When user selects a date on the calendar,
OnChange event is called ---> Here undo the date from the year :
 
 Do this with the standard functions delphi has.

Then 1. Filter Table (by giving date as filter) OR
            Prepare Query en Execute it (by filtering query with date)

---> That's all you need !!!

If you need source, just ask...! (Just give the format of the date)

Regards, ZIF.



0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jjhj
ID: 1336953
zif,

sorry for the delay
i've tried a few things but could you give me a sample of the
OnChange event and the filtered query sql.

Your 1,2.3 is basically correct

check what i've written so far ^

i would like to connect the panel caption, which displays the date selected by user, to query out the date from the table to a dbgrid

of course on birthdays the year has to be filtered out

jjhj
0
 

Author Comment

by:jjhj
ID: 1336954
zif,

sorry for the delay
i've tried a few things but could you give me a sample of the
OnChange event and the filtered query sql.

Your 1,2.3 is basically correct

check what i've written so far ^

i would like to connect the panel caption, which displays the date selected by user, to query out the date from the table to a dbgrid

of course on birthdays the year has to be filtered out

jjhj
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 100 total points
ID: 1336955
Yo jjhj,

I made this :

 One datasource, one table, one dbgrid, one edit, one button

 table (DBDEMOS, CUSTOMER.DB)
 datasource to table
 table to datasource.

If you fill the edit box, in a correct way (date entered like displayed in database; e.g. 17/11/94 14:10:33) and pushes on button than table is filtered on this datetime field..

What you've got to do is place the button commands into the onchange event of the calendar and use the selected date of the calendar to filter the table. BE SURE TO USE THE CORRECT FORMAT OF THE DATE TO FILTER THE TABLE

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids, DB, DBTables, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Table1: TTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Table1LastInvoiceDate: TDateTimeField;
    Table1CustNo: TFloatField;
    Table1Company: TStringField;
    Table1Addr1: TStringField;
    Table1Addr2: TStringField;
    Table1City: TStringField;
    Table1State: TStringField;
    Table1Zip: TStringField;
    Table1Country: TStringField;
    Table1Phone: TStringField;
    Table1FAX: TStringField;
    Table1TaxRate: TFloatField;
    Table1Contact: TStringField;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
 table1.Filtered := false;
 table1.Filter := '[LastInvoiceDate]='+''''+Edit1.text+'''';
 table1.Filtered := true;
end;

end.

Regards, ZIF.

Hope this is what you need, if not, just specify...


0
 

Author Comment

by:jjhj
ID: 1336956
zifnab

thanks

jjhj
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question