View Full Version : Mail Merge
DanielHowden
07-22-2011, 02:38 AM
I am trying to open a data source and merge certain fields. This is the code I have so far but I can't see how to extract the data from the file. As far as I can understand I have opened the data source but I now need to read it.
Cheers Daniel.
Sub Test()
Dim docNew As Document
Set docNew = ActiveDocument
With docNew.MailMerge
.MainDocumentType = wdCatalog
.OpenDataSource Name:="C:\Tuckswood.doc", ReadOnly:=True, Connection:="Ad1"
End With
End Sub
macropod
07-22-2011, 05:31 PM
Hi Daniel,
You need to Execute the merge!
...
.Execute
End With
DanielHowden
07-25-2011, 05:07 AM
Sorry, I forgot to add the .Execute line to my code. Yes I had got that far. What I am wanting to do is look at the data source data before I decide which bits to merge. Is this possible or not?
Cheers Daniel.
DanielHowden
07-25-2011, 07:54 AM
Found it, I did a watch on activedocument and found all the data in there. Thanks for the help anyway.
Cheers Daniel.
macropod
07-25-2011, 06:32 PM
Hi Daniel,
To filter the records interactively, I'd be inclined to use a SKIPIF field in the mailmerge main document. Suitably coded, a SKIPIF field can prompt you with relevant fields from each mailmerge record, and you simply input Y/N to say which ones to include/exclude.
DanielHowden
07-26-2011, 12:19 AM
Thanks for the pointer Paul. Ill keep that in mind because I am bound to want to scrutinise the data rather than just use it as is.
I have not found a ".NextRecord" function yet for mail merge. Do you know if there is one?
Cheers Daniel.
macropod
07-26-2011, 12:29 AM
Hi Daniel,
I'm not sure how you want to use it, but there's:
.MailMerge.DataSource.ActiveRecord = wdNextRecord
DanielHowden
07-26-2011, 12:35 AM
Hi Paul
my thinking is to use the mail merge datasource like a database and look at each record and decide if I want to use it.
Say I have a datasource of peoples names and addresses and I only want to use the male records, I would want to not use the female records. I guess I might have to build a temp datasource and then use that to merge to the document.
Cheers Daniel.
macropod
07-26-2011, 12:52 AM
Hi Daniel,
Why wouldn't you simply use a query to filter the records?
See: http://msdn.microsoft.com/en-us/library/aa140183(office.10).aspx
http://msdn.microsoft.com/en-us/library/aa140197(v=office.10).aspx
http://msdn.microsoft.com/en-us/library/aa220319(v=office.11).aspx
http://support.microsoft.com/kb/285333
DanielHowden
07-26-2011, 01:01 AM
Thanks Paul,
Ill take a look through those.
Cheers Daniel.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.