Solved

Delphi 7 :: Rave - Master Detail Report but do not print Detail for all Master records

Posted on 2007-11-30
10
2,087 Views
Last Modified: 2013-11-22
HI Experts,

I have a strange scenario, or maybe not. :)

My report mast print a master row and also where a certain fields is flagged, print the detail row for that particular master row.

In my master table I have a field by name: "PrintDetail" of type smallint.
If this fields = 1 then in Rave the detailed band should be printed else it should not be printed.

Can you please help.

Thanks in advance.
0
Comment
Question by:Marius0188
  • 4
  • 3
  • 3
10 Comments
 
LVL 13

Expert Comment

by:rfwoolf
ID: 20380562
Hi Marius

Yes you should set up a report and a dataconnection. Your one dataconnection will contect to your detail table. When you execute the report, your dataconnection will grab whatever fields are in that detail table.
I mean, you can even just use a filter if you like, which is what I do.
I say
Mytable.filtered := false;
Mytable.filter := 'MyField = ' + QuotedStr('77');
Mytable.filtered := true;
MyRaveReport.Execute;
MyTable.filtered := false;

For this purpose you can even use a TQuery if you prefer
0
 

Author Comment

by:Marius0188
ID: 20380665
Mmmh, I not sure if this is what I am looking for.

But close enough.

In the Rave report, some details records must be printed and others NOT.
Depending on a field value set in the Master table.

So somewhere in a OpPrinteDetailRecordsEvent()
I should be able to do something like this code:

If MasterTables.FieldByName('PrintDetail').AsInteger = 1 then
begin
  //Allow printing of detail records for this Master record because "PrintDetail" is flagged.
end
Else
begin
  AbortPrinting;
  //Do not print this detail records because the Master field "PrintDetail" is not flagged.
end;
0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 20380737
Yeah, use a filter on a table or else a query on a Query
Do you know how to use DataConnections? (I think you have to know any way),
so just connect your Query or your Filtered Table to the dataconnection.

Let me know if you need help with the SQL code or filter, although the filter should be quite easy.

So maybe something like this:
If MasterTables.FieldByName('PrintDetail').AsInteger = 1 then
begin
   DetailTable.filtered := false;
   DetailTable.filter := 'KEYFIELD = 1';
   DetailTable.filter := True;
   MyRaveReport.Execute;
end
Else
begin
  showmessage('Sorry, there are no detail records to print!');
end;
0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 20380745
The query version would be something like this:

So maybe something like this:

begin

   MyDetailQuery.SQL.clear;

   MyDetailQuery.SQL.Add('SELECT * FROM MyDetailTable WHERE ((MyKeyField) = ' + MasterTable.FieldByName('PrintDetail').value + ')';

   MyDetailQuery.Open;

   If MyDetailQuery.RecordCount > 0 then

   MyRaveReport.Execute

   else

   Showmessage('sorry theres no detail records');

Open in new window

0
 

Author Comment

by:Marius0188
ID: 20380800
Sorry, maybe I am not understanding.

But I need this to happen on the fly while the Rave report is generating.
Because as the rave report are populated, only then will I know when to print detail records or not.

So that is why I am looking for a way to do this in the Rave report designer on a Event.

To give you a example:
qADO.SQL.Text := 'SELECT M.ID, M.Description, M.PrintDetail, D.ID, D.Qty FROM tblMaster M LEFT OUTER JOIN tblDetail D ON D.ID = M.ID';

// The above query will have a mixed combination of PrintDetail in one result set. PrintDetail can be one
// for Master Record #1 while it can be off for Master Record #2, all in the same result set. So this is
// why I need do a check on an Event or something similar before printing the detail records in the Rave
// Report.

I noticed that in Rave Report, your components do have events as well, but I have never worked with those before and are not sure what language you code there. Maybe some help here can reveal a solutions.

Thanks again.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 13

Expert Comment

by:rfwoolf
ID: 20380845
Okay sorry I don't really have experience with something like that. What i do know is that if you want to populate all your results in a Query and then execute the Rave Report that's one way.
Good luck
0
 
LVL 21

Accepted Solution

by:
developmentguru earned 500 total points
ID: 20381680
I have a rave report that has several bands doing what you want to do.  In th first band in the OnBeforePrint method I do code like this for each band to determine if it will be visible.

  //Quantity Discount Band
  if dvSOItemsnDiscRateq.AsFloat = 0.00 then
    dbQuantityDiscount.Visible := false;
  else
    dbQuantityDiscount.Visible := true;
  end;

Substitute a comparison to your field and that should do it for you.  Let me know how it goes.
0
 
LVL 21

Expert Comment

by:developmentguru
ID: 20381686
Sorry, that should have read as "In the first DETAIL band".
0
 

Author Comment

by:Marius0188
ID: 20394015
HI developmentguru,

I have inserted this code as you suggested:

if dvPartsPrintBom.AsInteger = 0 then
  PartBoms.Visible := false;
else
   PartBoms.Visible := true;


But when clicking the compile button in rave report then I receive a error message:
Error #2 - [If] expected.

What is wrong?

Please help.
0
 
LVL 21

Expert Comment

by:developmentguru
ID: 20395183
One quick thing you can try is comparing
  .AsFloat = 0.00
      or
  .AsBoolean = True
This AsFloat is the comparison that is working for me, although my field is a floating point type.  There are some odities in the comparisons used in Rave.  I have noticed some around the comparisons with boolean values anyway.

  If that does not work, be sure to paste all of the text (in the gray areas above your code too, so I can tell where it has been placed.  Of course you would need to be sure that the component names match your components.  Here is the full code that is working in mine (gray areas included).  I placed it in my first detail data band.


-------------------------------------------------------------------------------------------------------------
{ Event for dbItemMain.OnBeforePrint }

function dbItemMain_OnBeforePrint(Self: TRaveDataBand);

begin
  //Quantity Discount
  if dvSOItemsnDiscRateq.AsFloat = 0.00 then
    dbQuantityDiscount.Visible := false;
  else
    dbQuantityDiscount.Visible := true;
  end;

  //System Discount
  if dvSOItemsnDiscRatsd.AsFloat = 0.00 then
    dbSystemDiscount.Visible := false;
  else
    dbSystemDiscount.Visible := true;
  end;

  //Special Discount
  if dvSOItemsnDiscRates.AsFloat = 0.00 then
    dbSpecialDiscount.Visible := false;
  else
    dbSpecialDiscount.Visible := true;
  end;

  //Warranty Discount
  if dvSOItemsnDiscRatew.AsFloat = 0.00 then
    dbWarrantyDiscount.Visible := false;
  else
    dbWarrantyDiscount.Visible := true;
  end;

  //Dealer Discount
  if dvSOItemsnDiscRated.AsFloat = 0.00 then
    dbDealerDiscount.Visible := false;
  else
    dbDealerDiscount.Visible := true;
  end;
end OnBeforePrint;
-------------------------------------------------------------------------------------------------------------
If none of this helps... what version of Rave are you using?
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now