I created a macro that propagates labels from a .csv file. I used this technique because the report could generate anywhere from 1 - 3000 labels, and just creating a mail merge doc that is linked to the dataset was only generating the same amount of labels as used in the original dataset. The dataset also has no header row, so I had to bring it into a table so that I could insert a header row for mail merge fields.

However, it turns out that Word cannot open the database when there is only one record.

Any suggestions on a work around for this eventuality?

VB Code:
  1. Sub TestTableLabels()
  2. '
  3. ' TestTableLabels Macro
  4. ' Macro recorded 7/30/2005 by User
  5.  
  6. 'Create Word table from dataset so header rows can be inserted
  7. Dim DataTable As Table
  8. Dim FirstRow As Row
  9. Dim CurCell As Cell
  10. Dim i As Integer
  11.  
  12. Dim Doc1 As Document
  13. Dim Doc2 As Document
  14.  
  15. Set Doc1 = ActiveDocument
  16.  
  17. ActiveDocument.Select
  18.  
  19. With Selection
  20.     .Collapse Direction:=wdCollapseEnd
  21.     .Range.InsertDatabase _
  22.         Format:=wdTableFormatSimple2, Style:=191, _
  23.         LinkToSource:=False, Connection:="Entire Spreadsheet", _
  24.         DataSource:="C:\Me\Reference\Work\labels.csv"
  25. End With
  26.  
  27. Set DataTable = ActiveDocument.Tables(1)
  28.  
  29. Set FirstRow = DataTable.Rows.Add(BeforeRow:=DataTable.Rows(1))
  30.  
  31. For Each CurCell In FirstRow.Cells
  32.  
  33.     CurCell.Range.InsertAfter Text:="Cell " & i
  34.     i = i + 1
  35.    
  36. Next CurCell
  37.  
  38.  
  39. ActiveDocument.SaveAs FileName:="C:\Me\Reference\Work\LabelTable.doc", _
  40.     FileFormat:=wdFormatDocument
  41.  
  42. 'ActiveDocument.Close
  43.  
  44. 'Create the mailmerge
  45. Application.MailingLabel.DefaultPrintBarCode = False
  46. Application.MailingLabel.CreateNewDocument Name:="5161"
  47.  
  48.     ActiveDocument.MailMerge.MainDocumentType = wdMailingLabels
  49.     ActiveDocument.MailMerge.OpenDataSource Name:= _
  50.         "C:\Me\Reference\Work\LabelTable.doc", ConfirmConversions:=False, _
  51.         ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
  52.         PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
  53.         WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
  54.         Connection:="", SQLStatement:="", SQLStatement1:="", SubType:= _
  55.         wdMergeSubTypeOther
  56.     ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _
  57.         , Text:="""Cell_0"""
  58.     ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _
  59.         , Text:="""Cell_1"""
  60.     ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _
  61.         , Text:="""Cell_2"""
  62.     ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _
  63.         , Text:="""Cell_3"""
  64.     ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _
  65.         , Text:="""Cell_4"""
  66.     Selection.MoveLeft Unit:=wdCharacter, Count:=5, Extend:=wdExtend
  67.     Selection.Font.Size = 11
  68.     Selection.MoveLeft Unit:=wdCharacter, Count:=1
  69.     Selection.MoveRight Unit:=wdCharacter, Count:=8
  70.     Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(3.76), _
  71.         Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces
  72.     Selection.ParagraphFormat.TabStops(InchesToPoints(3.76)).Position = _
  73.         InchesToPoints(3.88)
  74.     Selection.TypeText Text:=vbTab
  75.     Selection.MoveRight Unit:=wdCharacter, Count:=8
  76.     Selection.TypeParagraph
  77.     Selection.TypeParagraph
  78.     Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
  79.     Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
  80.     Selection.Font.Bold = wdToggle
  81.     Selection.MoveRight Unit:=wdCharacter, Count:=1
  82.     Selection.TypeParagraph
  83.     Selection.TypeParagraph
  84.     Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
  85.     Selection.MoveRight Unit:=wdCharacter, Count:=8
  86.     Selection.TypeText Text:=vbTab
  87.     Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
  88.     Selection.Font.Size = 9
  89.     Selection.MoveRight Unit:=wdCharacter, Count:=1
  90.     WordBasic.MailMergePropagateLabel
  91.    
  92. Set Doc2 = ActiveDocument
  93.    
  94.     With ActiveDocument.MailMerge
  95.    
  96.         .Destination = wdSendToNewDocument
  97.         .SuppressBlankLines = True
  98.        
  99.         With .DataSource
  100.        
  101.             .FirstRecord = wdDefaultFirstRecord
  102.             .LastRecord = wdDefaultLastRecord
  103.            
  104.         End With
  105.        
  106.         .Execute Pause:=False
  107.        
  108.     End With
  109.  
  110. Doc1.Close
  111. Doc2.Close (wdDoNotSaveChanges)
  112.    
  113. End Sub