How To…Skip Printing a Defined Number of Labels

Question

“How do I start printing on the label of my choice when printing to a label sheet such as Avery?”

Solution

Use the DetailBand.BeforePrint event to keep track of the label that is being printed.  Then toggle the visibility of the components in the detail band based on which labels you would like to print.
This can be helpful for instances where you are printing to a label template page with individual labels missing or that have already been used.

Download: SkipLabels.zip

SkipLabelsRAP.zip

Sample Delphi code:

procedure TForm1.InitializeReport;
begin
  ppReport1.DetailBand.BandsPerRecord := FSkip + FLabelsPerRecord;
  FTotalBandsPerColumn := 0;
  ppDBCalc1.Visible := False;
  ppDBText1.Visible := False;
end;

procedure TForm1.ppReport1StartPage(Sender: TObject);
begin
  if (ppReport1.AbsolutePageNo = 1) then
    InitializeReport;
end;

procedure TForm1.ppDetailBand1BeforePrint(Sender: TObject);
var
  liBandsGenerated: Integer;
begin

  liBandsGenerated := ((ppReport1.CurrentColumn - 1) * FTotalBandsPerColumn) + ppReport1.DetailBand.Count;

  if (liBandsGenerated = FSkip) then
    begin
      ppDBCalc1.Visible := True;
      ppDBText1.Visible := True;
    end
  else if (liBandsGenerated = FSkip+FLabelsPerRecord) and (ppReport1.DataPipeline.RecordNo = 1) then
    ppReport1.DetailBand.BandsPerRecord := FLabelsPerRecord;

end;

procedure TForm1.ppReport1EndColumn(Sender: TObject);
begin
  if (FTotalBandsPerColumn = 0) then
    FTotalBandsPerColumn := ppReport1.DetailBand.Count;
end;