Solved

Query Question

Posted on 1998-04-25
7
147 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
Technology Partners: 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 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