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 & "\secondcontact.pub", "publisher.document")
    objPub.MailMerge.OpenDataSource _
        bstrDataSource:=CurrentDb.Name, _
        bstrTable:="tempSecondContact", _
        fNeverprompt:=True, fopenexclusive:=True
       
    objPub.MailMerge.Execute True
dfisher6Asked:
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.

pteranodon72Commented:
your line:
Set objPub = GetObject(CurrentProject.Path & "\secondcontact.pub", "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 & "\secondcontact.pub")

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.

HTH,

pT
0
dfisher6Author Commented:
Thank you! That worked - it merged directly to a printer. Can it merge to print preview (as I ususally do in word)?
0
pteranodon72Commented:
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.

HTH,

pt
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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?
0
pteranodon72Commented:
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!

HTH,

pT
0

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.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.