Launching a publisher document from access using mail merge and VBA

I am trying to do  a publisher mail merge from VBA code in the access db holding the merge info. I have done this successfully into Word, but cannot get publisher to work. I am receiving a 432 error (file or class not found). Here is the code:
Dim appPub As Publisher.Application
    Set appPub = New Publisher.Application
    Dim objPub As Publisher.Document
    Set objPub = GetObject(CurrentProject.Path & "\", "publisher.document")
    objPub.MailMerge.OpenDataSource _
        bstrDataSource:=CurrentDb.Name, _
        bstrTable:="tempSecondContact", _
        fNeverprompt:=True, fopenexclusive:=True
    objPub.MailMerge.Execute True
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

your line:
Set objPub = GetObject(CurrentProject.Path & "\", "publisher.document")

looks really suspicious.  You only need GetObject if you want to avoid having a reference to Publisher and use late binding.

Since you create a new instance of Publisher, use the Open method of the object to set the document.

Set objPub = appPub.Open(CurrentProject.Path & "\")

The rest should follow OK.
For getObject to work, the document would have to already be open.  You could use CreateOjbect, but you've already got the app, use its methods instead.


dfisher6Author Commented:
Thank you! That worked - it merged directly to a printer. Can it merge to print preview (as I ususally do in word)?
It's not really quite a Print Preview but why not replace your .Execute line with

Dim docResult as Publisher.Document
Set docResult =  objPub.MailMerge.Execute(True, pbMergeToNewPublication)

This executes the merge into a new document, which you can look at and decide to save or not.

If you go into the Access module code, press F2 to see the object browser. Choose the publisher library and then you'll be able to see all of the methods of the Application, Document, and MailMerge objects to pick up their parameter possibilities.


Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

dfisher6Author Commented:
Thank you again - one more question? It merges each record into a postcard twice. I haven't found any parameter with number of copies. Any ideas on that?
The only thing I can think of is that some postcard templates are two pages, so the merged result should be 2 * #records pages.  Or, if you're using pbMergeToExistingPublication, you'll append new  pages every time each time you execute.  Last resort -- check you number of records in your datasource!



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dfisher6Author Commented:
Thanks for the help - none of the suggestions was the case for double pages, but as long as they are able to open in preview mode, they can just print the ones needed.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.