Solved

Query Question

Posted on 1998-04-25
7
144 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

773 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