Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QuickReports - Missing Something? 1

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I have created a new form, dropped a QuickReport component, added a title band, column header band and a detail band. I have query that I have set as the DataSource of the report.

From what I have read in the help, that should be all I need to do to get my report, but it's always blank. Am I missing something? How do I get the detail into the detail band?

Any help appreciated!

leslie
 
The simple answer is to just place a QRDBText into your Detailband and assign it to your query and give it the expected field name (much in the same way as a DBEdit box works). That should at the very least place the first record in your query onto your report.

Depending on how complex your report is you then have to start using QRGroups and QRExpressions to see anything better than just a straightforward list report. Also, it can be quite hard to dig up any support on QuickReports but Ive used it pretty extensively in the past so post back if you have any queries regarding what you can and cant do with it.

[blue]"Now you see that evil will always triumph, because good is dumb" - Dark Helmet[/blue]
 
Thanks for the help, I'll work on this and will definitely post back with any problems

Leslie
 
Ok, maybe I'm going about this the wrong way. Here's what I'm trying to accomplish. I am creating a dynamic report generator. The user selects what kind of report to run, depending on the choice, the query is prepared and run. Then I want to display the data of the query. Except depending on the choices selected, the fields and columns are different. For instance, there are two Assignment reports - Criminal and Civil. The Criminal Assignment Reports has data that is like:

Code:
ASNJUD  JUDNAM                CHGTYP     COUNT     SORT
  1     Victor Valdez            D         259       1
  1     Victor Valdez            V         158       2
  1     Victor Valdez            M         872       3
  1     Victor Valdez            T        3293       4
  1     Victor Valdez            P          97       5
  1     Victor Valdez            W        4679       6
  1     Victor Valdez            Z        3456       7
  2     Kevin Fitzwater          D         257       1
  2     Kevin Fitzwater          V         152       2
  2     Kevin Fitzwater          M         897       3
  2     Kevin Fitzwater          T        3233       4
  2     Kevin Fitzwater          P          95       5
  2     Kevin Fitzwater          W        4634       6
  2     Kevin Fitzwater          Z        4529       7
  3     Frank Sedillo            Z          62       7

notice the last entry for ASNJUD 3 - he doesn't have any of the other results, just 'Z' results

This translates to:

D - DWI Cases
V - Domestic Violence
M - Misdemeanor
T - Traffic
P - Parking
W - Total Assignments
Z - Total Dispositions

I need the query information displayed as:

Code:
Division    Judge      DWI   DV   Misd   Traffic  Park  Total  Dispos
1      Victor Valdez   259   158   872   3293     97     4679   3456
2      Kevin Fitzwater 257   152   897   3233     95     4634   4529
3      Frank Sedillo                                             62
[b]Totals[/b]

Now the civil query displays different information, same structure for the source, but it needs to be displayed as:
Code:
Case Type         Sedillo        Ramczyk       Martinez
Breach of Contract  299            253            260
Bad Check             3              3              1
Debts               898            656            757
Forcible Entry       16              4              7
Mobile Home         120             96             83
Other                21             14             19
Personal Injury       3              1              1
Property              6              2              2
Restitutions       1703           1134           1244
Replevin                                            1
Wages                 1                             1
[b]Totals[/b]

Is there an easy way to tie these two data sources to the same QuickReport and change the report specifications dynamically depending on the report selected?

Thanks!

Leslie
 
Looking at the information that you have provided, I would say that yes it is possible to do this as one QuickReport as both documents will use the same layout albeit with different data. Essentially, what you want is a Quickreport with two QRBands and one QRGroup. Of the two bands, one should be assigned as a detail band and the other should be a footer band. The footer band has a link property and this should be your QRGroup band.

In the detail band, you need to place your QRDBTexts which relate to the records you wish to show on the document. Both the QuickReport itself and the QRDBTexts need to be assigned a dataset (your query) and the QRDBTexts also need to be assigned the relevant fieldnames. These can obviously be done dynamically at runtime. The only problem I can forsee you having is where you need more fields on one report than you do on the other. Personally, I would just place X amount of QRDBTexts on the report and then set the values at runtime leaving any unused QRDBTexts out of the equation.

So, what you have so far is a report which displays ALL of the records you dataset has returned. If I understand correctly, you want the TOTALS displaying instead of all records. To do this, you need to replace your QRDBTexts with QRExprs and look at the GroupBands Expression value. Whatever field you elect to place in the GRGroups Expression value will then display the data grouped by that value (i.e. JUDNAM). You can then use the QRExpr in exactly the same way to display the totals. For example, typing SUM(COUNT) into the QRExprs Expression property would only display one record for each JUDNAM number and that value would be the total of the field JUDNAM.

The expressions can be a bit fiddily to get working correctly at times but there is an Expression builder available via the Object Inspector to help out.

Hope this helps. Pretty sure Ive rambled a bit towards the end.

[blue]"Now you see that evil will always triumph, because good is dumb" - Dark Helmet[/blue]
 
actually I need both detail and totals in the final report and your rambling!!

I've never worked with the quick reports because I've never been able to figure out all the pieces that put it all together. I think I'll start out with trying to create a single report statically until I get a better feel for how the reports work.

Any more information you feel like sharing on how to build reports will be appreciated, (any code you have that would help...[spineyes])

Les
 
Theres very little actual code involved, the power of QuickReports comes from the components themselves and the report layout. You only really need a few lines of code to open your dataset and then to call the quickreport.

Depending on which version of Delphi you are using, in your Delphi installation folder there should be a Demos folder which contains a comprehensive QuickReport example. If you have it, take a look and you should be able to see how the QRbands link up correctly.

[blue]"Now you see that evil will always triumph, because good is dumb" - Dark Helmet[/blue]
 
Les, check out in their download area are tutorials. Like Eric stated there is not a lot of hardcoding involved but in the tutorials the working of components is described very well.

Regards

Steven
 
Ok, here's why I'm confused. You say that there isn't much code to the QuickReports, but here's what is "creating" the Report based on the values in a string grid:

Code:
unit Unit_QRCasesAssigned;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  qrctrls, qrprntr, ExtCtrls, QuickRpt, jpeg, Grids, StdCtrls;

type
  TForm_QRCasesAssigned = class(TForm)
    QuickRep1: TQuickRep;
    TitleHeaderBand1: TQRBand;
    ColumnHeaderBand1: TQRBand;
    DetailBand1: TQRBand;
    QRLabel1: TQRLabel;
    QRLb_Title: TQRLabel;
    QRImage1: TQRImage;
    QRLabel3: TQRLabel;
    QRLabel4: TQRLabel;
    QRLb_FromDate: TQRLabel;
    QRLb_ToDate: TQRLabel;
    PageFooterBand1: TQRBand;
    StaticText1: TStaticText;
    StaticText2: TStaticText;
    StaticText3: TStaticText;
    StaticText4: TStaticText;
    procedure CreateLabels;
    procedure FreeLabels;
    procedure QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
    procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
      var PrintReport: Boolean);

  private
    { Private declarations }
  public
    { Public declarations }
    RowCounter,
    MaxCols : integer;
    ColumnLabels: array[0..29] of TQRLabel;
    DataLabels: array[0..29] of TQRLabel;
    QRStringGrid : TStringGrid;
  end;

var
  Form_QRCasesAssigned: TForm_QRCasesAssigned;

implementation

uses Unit_CasesAssigned, Unit_Main;


{$R *.DFM}

procedure TForm_QRCasesAssigned.CreateLabels;
var
  nIndx: integer;
begin
  QRLb_Title.caption:='Case Managment Statistics - Case Assignments';
  QRLb_FromDate.caption:=DateToStr(Form_Main.DateTimePicker1.Date);
  QRLb_ToDate.caption:=DateToStr(Form_Main.DateTimePicker2.Date);
  with Form_CasesAssigned.StringGrid1 do
  begin
    nIndx:=0;
    MaxCols := ColCount;
    while nIndx <= MaxCols do
    begin
      ColumnLabels[nIndx]:=TQRLabel.Create(Self);
      with ColumnLabels[nIndx] do
      begin
        Parent := QuickRep1.Bands.ColumnHeaderBand;
        Height := Parent.Height;
        AlignToBand := False;
        Top := 0;
        Autosize := false;
        Width :=ColWidths[nIndx];
        Font.Size := 8;
        // Grab the captions from the StringGrid
        Caption := Cells[nIndx, 0];
        if nIndx = 0 then
          Left := 0
        else begin
          Left := ColumnLabels[nIndx-1].Left + ColumnLabels[nIndx-1].Width + 2
        end;
        if nIndx = 0 then alignment := taCenter else
          if nIndx = 1 then alignment := taLeftJustify else
            alignment := taRightJustify;
        DataLabels[nIndx] := TQRLabel.Create(Self);
        with DataLabels[nIndx] do
        begin
          if nIndx = 0 then alignment := taCenter else
            if nIndx = 1 then alignment := taLeftJustify else
              alignment := taRightJustify;
          Parent := QuickRep1.Bands.DetailBand;
          Height := Parent.Height;
          AlignToBand := False;
          Top := 0;
          Autosize := false;
          // Size the detail labels to match the horizontal properties of the
          // column header labels so that they line up evenly
          Left := ColumnLabels[nIndx].Left;
          Width := ColumnLabels[nIndx].Width;
        end;
        Inc(nIndx);
      end;
    end;
  end;
end;

procedure TForm_QRCasesAssigned.FreeLabels;
var
  nIdx: integer;
begin
  for nIdx := 0 to 29 do
  begin
    if ColumnLabels[nIdx] <> nil then
    begin
      ColumnLabels[nIdx].Free;
      ColumnLabels[nIdx] := nil;
    end;
    if DataLabels[nIdx] <> nil then
    begin
      DataLabels[nIdx].Free;
      DataLabels[nIdx] := nil;
    end;
  end;
end;


procedure TForm_QRCasesAssigned.QuickRep1NeedData(Sender: TObject;
  var MoreData: Boolean);
var
  nIdx: integer;
begin
  with Form_CasesAssigned.StringGrid1 do
  begin
    MoreData := RowCounter < RowCount;
    // start with the first column in this row
    nIdx := 0;
    while nIdx <= MaxCols do
    begin
      with DataLabels[nIdx] do
      begin
        // Get the current data
        Caption := Cells[nIdx, RowCounter];
      end;
      // Move to the next column in this row
      Inc(nIdx);
    end;
    // Move to the next column
    Inc(RowCounter);
  end;
end;

procedure TForm_QRCasesAssigned.QuickRep1BeforePrint(
  Sender: TCustomQuickRep; var PrintReport: Boolean);
begin
  RowCounter:=1;
end;

end.

Now I have added the PageFooter band to this report. In that band I have added 5 StaticText boxes for Report Notes. And the Footer doesn't show up at all!

Is there something in this code which would repress the PageFooter band? Is there something that I need to add to have it show up?

Thanks for any pointers!

les
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top