Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count Merged Records

Status
Not open for further replies.

Smoothas

IS-IT--Management
May 1, 2002
93
GB
Hello,

I;ve created a word macro that opens a label template, selects record source, and performs the merge.

What I would now like to do , it add a message box that tells me how many records were merged / labels were created.

I got it to count the number of pages using :-
MsgBox ActiveDocument.Sections.Count & " Pages."
but not all the pages a "Full", so I am really after the number of records merged / labels populated.

Any Ideas?

Many thanks in advance.
 
As long as you work with template document and have live connection to data source, you can:
MsgBox ActiveDocument.MailMerge.DataSource.RecordCount


combo
 
Thanks again combo.
When I add that into my macro, a message box come up with the value -1 ????

This is my macro :-

Sub MergeStickers()
'
' MergeStickersMacro
' Macro recorded 3/19/2007 by GOakham
'
strFileZ = Format$(Date, "yy-mm ")
Const sFILE As String = "Fulfillment"
Const sPATH As String = "\\Solaris\Operations\Clients\Stickers\"
Const sVAR As String = ""


ChangeFileOpenDirectory "\\Server\Dir\Dir2\Dir3\"
Documents.Open FileName:="New Merge Settings.doc", ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:=sPATH & sVAR & _
Format(Now - 1, "dd-mm-yy ") & sFILE & ".csv" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="", SQLStatement1 _
:="", SubType:=wdMergeSubTypeOther
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
' Windows("New Merge Settings 2.doc").Activate
' ActiveWindow.ActivePane.VerticalPercentScrolled = 0
' Windows(1).Activate
'MsgBox ActiveDocument.Sections.Count & " Pages."
MsgBox ActiveDocument.MailMerge.DataSource.RecordCount
MsgBox "Auto Merge complete.", vbInformation, "Phew...Finished"
End Sub

Thanks again
 
Try test on the source document (after mail merge the output document is only a sequence of sections, without link to data source):
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
[!]MsgBox .RecordCount[/!]
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With


combo
 
Hi, Thanks again for the quick repsonce Combo.
This still givens me the count of -1.
I've put it where you have suggested, and after the .lastRecord line aswell, but still get the same result. Weird.
Any other ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top