Solved

Query Question

Posted on 1998-04-25
7
148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

615 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