I am trying to go through a data source for a word mail merged document.
My code to run through the mail merge data source looks like this:
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord
lastDoc = ActiveDocument.MailMerge.DataSource.RecordCount
Now everything works really well. I run through the data source and do what I need to do.
Now the user that I am making this for are, due to other reasons, using the small helper function: Mail Merger Helper (it exists in Word 2010)
When they use this however, my ActiveDocument.MailMerge.DataSource.RecordCount returns -1. Which means that it can't decide the number of records in the datasource. My assumption is that the Mail Merger Helper doesn't set the datasource correctly.
But that prevents me from iterating the mail merge (when he uses the helper, he can still activate the usual mail merge functions such as seeing the result of the merge).
What is wrong? Is there an alternative to iterating the merge, so I can get the records one by one?
Thank you bibadia, you lead me down the right track.
When you set the ActiveRecord to wdLastRecord. You can read the last data source off of ActiveRecord. So I just needed to grab that, and then set ActiveRecord to wdFirstRecord again.
Dim count As Integer
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord
count = ActiveDocument.MailMerge.DataSource.ActiveRecord
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord