Microsoft KB Archive/114256

From BetaArchive Wiki
Knowledge Base


How to Duplicate Varying Number of Labels Per Record

Article ID: 114256

Article Last Modified on 12/3/2003



APPLIES TO

  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft FoxPro 2.5b
  • Microsoft FoxPro 2.5a
  • Microsoft FoxPro 2.5b
  • Microsoft FoxPro 2.6 Standard Edition
  • Microsoft FoxPro 2.5b for MS-DOS
  • Microsoft FoxPro 2.5a
  • Microsoft FoxPro 2.5b for MS-DOS
  • Microsoft FoxPro 2.6 for MS-DOS



This article was previously published under Q114256

SUMMARY

While article 106030, "How to Print Multiple Copies of the Same Label", describes a method to produce a fixed number of duplicate labels, this article addresses those situations where the number of times each label is to be duplicated must vary.

MORE INFORMATION

This example uses the following files:

   XLABEL.DBF - label data records with an additional count field (DUP)
   DUPLIX.DBF - database that holds the duplicated records; recreated each
                session
   DUPLABEL.LBX (and .LBT) - label layout form referencing DUPLIX fields
   DUPLABEL.PRG - program that fills DUPLIX database with duplicates
                

To set up the files:

  1. Create (or modify) the data file (XLABEL.DBF) structure to contain a numeric field (DUP) that will hold the number that indicates how many times each label is to be copied.
  2. To create DUPLIX, issue this command:

          CREATE duplix
                            

    DUPLIX contains those fields from XLABEL.DBF that will be used by the label form. If you want all the fields, issue the following commands, and then remove the count field DUP from the DUPLIX structure:

          USE XLABEL
          COPY STRUCTURE to DUPLIX
  3. Issue the following command, using the fields found in DUPLIX:

          CREATE LABEL DUPLABEL
                            

    In Visual FoxPro, add the DUPLIX table to the Data Environment of the label.

  4. Issue the MODIFY COMMAND DUPLABEL command, and then enter the following code:

          SET TALK OFF
    
          * Open databases.
          IF USED('DUPLIX')
             SELECT duplix
          ELSE
             USE duplix
          ENDIF
          SELECT 0
          IF USED('XLABEL')
             SELECT xlabel
          ELSE
             USE xlabel
          ENDIF
    
          * Create blank merge file.
          SET SAFETY OFF
          SET TEXTMERGE TO hold
          SET SAFETY ON
          SET TEXTMERGE ON NOSHOW
    
          * Cycle through labels, outputting each to the HOLD file
          * for the number of times stated in XLABEL.DUP field.
          SCAN
             FOR i=1 TO xlabel.dup
                \\<<xlabel.co>><<xlabel.contact>><<xlabel.addr>>
                \ 
             ENDFOR
          ENDSCAN
          * NOTE: The double backslash prevents an initial carriage return,
          * which would result in the first label being blank when printed.
    
          * Close the merge file.
          SET TEXTMERGE OFF
          SET TEXTMERGE TO
    
          * Prepare the DUPLIX database to receive the new labels.
          SELECT duplix
          SET SAFETY OFF
          ZAP
          SET SAFETY ON
    
          * Add in the new labels to the blank DUPLIX database.
          APPEND FROM hold.txt TYPE SDF
    
          * Send out the labels.
          LABEL FORM duplabel PREVIEW
                            

NOTE: The PREVIEW option can be replaced by or used with TO PRINT to send the labels to the printer.


Additional query words: VFoxWin FoxDos FoxWin repeat

Keywords: kbcode KB114256