Home End User
New Blog Posts: Merging Reports - Part 1 and Part 2

Adding a search criteria based on current date

edited February 2004 in End User
Is there a way to add a date field into the search criteria of an end-user
report and have it always default to the current day when the report is
run??

Thanks In Advance,
Stacey

--

Regards,
Stacey R. Brodsky
ClubRunner, Inc.
(561) 746-3392

www.clubrunner.net

Comments

  • edited February 2004
    I should mention, that I am trying to do this all in the end-user report
    create dialogs. So, I am using the data tab for my criteria, and hoping,
    that I can set it somewhere on the calc tab. I would like to avoid any
    coding at design time so that my users can create their own reports.

    Also, using D5 and RB 6 (I think)

  • edited February 2004
    Hi Stacey,

    You can set the SearchExpression of the AutoSearchDialog before it gets
    created in the Report.BeforeAutoSearchDialogCreate event. Inside here you
    can use the Report.AutoSearchFields[].SearchExpression to define the default
    autosearch value for the dialog. If you do not want to see the dialog, you
    can set the Report.ShowAutoSearchDialog to False.

    Here is a quick example.

    procedure TForm1.ppReport1BeforeAutoSearchDialogCreate(Sender: TObject);
    begin
    ppReport1.AutoSearchFields[0].SearchExpression := DateToStr(Now());
    end;

    Note: I created this autosearch field already in DADE.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2004
    Yes, that is what I want to do, but how do I do this without any code at
    design-time??? These are end-user created reports, created at run-time.


  • edited February 2004
    Hi Stacey,

    You can do this completely at runtime using RAP. RAP (Report Application
    Pascal) is ReportBuilder's run-time Pascal development environment. RAP
    enables the entire report definition (Data, Calculations, and Layout) to be
    stored outside of the application executable. Using RAP you could define the
    Report.BeforeAutoSearchDialogCreate event completely in the Report
    definition without the need for any Delphi code. RAP only comes with the
    Enterprise edition of ReportBuilder. If you would like to find out if it
    will work for you, please consider downloading a trial version of
    ReportBuilder Enterprise 7.03 and testing with that.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2004
    Hi Nico,
    Thanks for answering so far. I do have an Enterprise edition...v6.03. I have
    the calc tab and I can get to Report.BeforeAutoSearchDialogCreate...but, I
    can not get anything to compile in there. I am using
    AutoSearchFields[?]...or whatever the name is, but it will not
    compile...doesn't understand what AutoSearchFields[?] is??

    Any suggestions as to what I am doing wrong?

    Thanks,
    Stacey
  • edited February 2004
    I'm getting there...in ReportBeforeAutoSearchDialogCreate I have the
    following code...

    begin
    Report.AutoSearchFields[1].Value := CurrentDate;
    end;

    I also threw up a memo to show me the search criteria. When running the
    report, the memo still shows the original 'fake' date I put in for the
    Value...and, when hitting the search criteria button to change it, I get an
    error : Could not run program : ReportBeforeAutoSearchCreate. If I hit it a
    second time, it comes up, but still with the original 'fake' value.

    Again...now where am I going wrong?

    Stacey



  • edited February 2004
    Hi,

    The following code worked for me... Hope this helps.

    procedure ReportBeforeAutoSearchDialogCreate;
    begin
    Report.AutoSearchFields[0].SearchExpression := DateToStr(CurrentDate);
    end;

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2004
    That worked...thank you so much.


  • edited February 2004
    Stacey,

    another approach would be to extend the autosearch classes, as shown in the
    code below (unfortunately the code is commented in german), so
    autosearchfields of type date are recogniced automatically and the calendar
    drop down appears. Of course setting today as default is then easy too.

    HTH
    Bernd

    {
    Description:
    Diese Unit dient um neue AutoSearchPanels zu erzeugen und im
    ReportBuilder zu registrieren.
    Es steht ein Datum-SearchPanel zur Verf?gung, sodass, wenn das Datum als
    Autosuchfeld angegeben wird, der
    DateTimePicker angezeigt wird um das gew?nschte Datum einzugeben.

    History:
    JES 2002.12.07 created
    }
    unit AutoSearchDialog;

    interface

    uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    StdCtrls, ExtCtrls, ppForms, ppASCtrl, ppDB, ppTypes, ppUtils, ppASDlg,
    ComCtrls, ppASField;

    type
    // Die Klasse TAdvanceAutoSearchDialog dient um beim Anzeigen des
    Suchdialoges, den richtigen abzufangen und
    // anzuzeigen.
    TAdvanceAutoSearchDialog=class(TppAutoSearchDialog)
    protected
    // Die Methode GetPanelClassForField ?berpr?ft, ob es sich beim
    darzustellenden Suchfeld um einen von ReportBuilder
    // oder implementierten Suchdialog handelt. Falls es sich nicht um den
    von ReportBuilder handelt, wird die
    // entsprechende Klasse aufgerufen.
    procedure GetPanelClassForField(aField: TppAutoSearchField; var
    aPanelClass: TppAutoSearchPanelClass); override;
    end;

    // Die Klasse TDateSearchPanel dient um einen Datumssuchdialog anzuzeigen.
    TDateSearchPanel=class(TppSimpleSearchPanel)
    private
    dtSearchPicker: TDateTimePicker;
    protected
    procedure ShowAllValuesClickEvent(Sender: TObject); override;
    public
    // Die Methode Create erzeugt und initialisiert alle Objekte, die f?r
    diese Klasse notwendig sind.
    constructor Create(aOwner: TComponent); override;
    // Die Methode Destroy gibt wieder alle Objekte frei, die in dieser
    Klasse initialisiert worden sind.
    destructor Destroy; override;
    // Die Methode Init initialisiert DateTimePicker und setzt den richtigen
    Wert ein.
    procedure Init; override;
    // Die Methode Valid setzt das ausgew?hlte Datum ein, falls der Checkbox
    "Bedienung ausblenden" ausgeschalten bleibt.
    function Valid: Boolean; override;
    end;

    implementation

    procedure TAdvanceAutoSearchDialog.GetPanelClassForField(
    aField: TppAutoSearchField; var aPanelClass: TppAutoSearchPanelClass);
    begin
    if aField.DataType=dtDateTime then
    aPanelClass := TDateSearchPanel;
    end;

    constructor TDateSearchPanel.Create(aOwner: TComponent);
    begin
    inherited Create(aOwner);
    dtSearchPicker:= nil;
    end;

    destructor TDateSearchPanel.Destroy;
    begin
    FreeAndNil(dtSearchPicker);
    inherited;
    end;

    procedure TDateSearchPanel.Init;
    var
    stValues: TStrings;
    begin
    inherited;
    EditControl.Visible := False;

    dtSearchPicker:= TDateTimePicker.Create(Self);
    dtSearchPicker.Parent:= Self;
    dtSearchPicker.DateTime:= Now;
    dtSearchPicker.Left:= EditControl.Left;
    dtSearchPicker.Top:= EditControl.Top;
    dtSearchPicker.Width:= EditControl.Width;

    stValues:= TStringList.Create;
    ppParseString(Field.SearchExpression, stValues);
    if (stValues.Count > 0) then
    dtSearchPicker.Date := ppStrToDateTime(stValues[0]);
    FreeAndNil(stValues);
    end;

    procedure TDateSearchPanel.ShowAllValuesClickEvent(Sender: TObject);
    begin
    inherited;
    dtSearchPicker.Enabled:= not(ShowAllValues.Checked);
    if (dtSearchPicker.Enabled) then
    dtSearchPicker.SetFocus;
    end;

    function TDateSearchPanel.Valid: Boolean;
    begin
    Result := True;
    Field.ShowAllValues := ShowAllValues.Checked;
    if not(Field.ShowAllValues) then
    Field.SearchExpression := DateToStr(dtSearchPicker.Date);
    end;

    initialization
    ppRegisterForm(TppCustomAutoSearchDialog, TAdvanceAutoSearchDialog);

    finalization
    ppUnRegisterForm(TppCustomAutoSearchDialog);

    end.
This discussion has been closed.