• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2258
  • Last Modified:

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

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
Marius0188
Asked:
Marius0188
  • 4
  • 3
  • 3
1 Solution
 
rfwoolfCommented:
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
 
Marius0188Author Commented:
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
 
rfwoolfCommented:
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
rfwoolfCommented:
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
 
Marius0188Author Commented:
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
 
rfwoolfCommented:
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
 
developmentguruPresidentCommented:
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
 
developmentguruPresidentCommented:
Sorry, that should have read as "In the first DETAIL band".
0
 
Marius0188Author Commented:
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
 
developmentguruPresidentCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now