Solved

Query Question

Posted on 1998-04-25
7
142 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jjhj
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
zifnab

thanks

jjhj
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now