MS Access code to convert word document into pdf

Hello everybody,
I have this question for a long time...
I am working in MS Access and I have made two buttons in my form.
One button generates a merge document and save it in a specific folder on my computer.
Second button, converts this word document into pdf document by printing it through "pdf995".

But whenever i click on this button a extra word document (document1) opens.
If i manually opens this word document and print it through pdf995, then it works fine.
The extra word document is only generated when i automatically (through code of button) try to convert it to pdf document.

The code I am using to convert this merge document into odf is as follows::::::

Set appWord = GetObject(, "Word.Application")
        strDefaultPrinter = appWord.ActivePrinter
        appWord.ActivePrinter = "PDF995"
        strWordDoc = Me.DocPath
        Set doc = appWord.Documents.Add(strWordDoc)
        doc.PrintOut
        Call Wait(6)
        appWord.ActivePrinter = strDefaultPrinter

DocPath is a name of field on my MS ACcess form, which contains the path of a merged(word) document which is to be converted to pdf.

Is the way to call pdf995 wrong???
Can anybody plz provide me with a code to convert this word document into pdf???
Thanx a lot!!!
John_BASAsked:
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.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
What version of Access/Word are you using?
0
John_BASAuthor Commented:
Hi,
Thanx for reply.
It is all MS Office2003
0
John_BASAuthor Commented:
Any solution or advice??
0
The Ultimate Tool Kit for Technolgy Solution Provi

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 for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

YohanFCommented:
I think what you have to do is open the document rather than adding - Set doc = appWord.Documents.open(strWordDoc)

I am not very familier with word print, however I found an article on this - http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_24878756.html

hope this help..
0
John_BASAuthor Commented:
Thanx YohanF,
i am going to try this out...
0
omgangIT ManagerCommented:
Try this.  OM Gang
Public Function PrintWordDoc()

On Error GoTo Err_PrintWordDoc

    Dim appWord As Word.Application
    Dim doc As Word.Document
    Dim strWordDoc As String, strDefaultPrinter
    
    strWordDoc = Me.DocPath
    
    Set appWord = CreateObject("Word.Application")
    appWord.Documents.Open (strWordDoc)
    Set doc = appWord.ActiveDocument

    strDefaultPrinter = appWord.ActivePrinter
    appWord.ActivePrinter = "PDF995"
        
    doc.PrintOut
    Call Wait(6)
    appWord.ActivePrinter = strDefaultPrinter

Exit_PrintWordDoc:
    Exit Function

Err_PrintWordDoc:
    MsgBox Err.Number & ", " & Err.Description, , "Error in Function PrintWordDoc of Module Module6"
    Resume Exit_PrintWordDoc

End Function

Open in new window

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
omgangIT ManagerCommented:
Actually, try this one with a few changes.  OM Gang
Public Function PrintWordDoc()

On Error GoTo Err_PrintWordDoc

    Dim appWord As Word.Application
    Dim doc As Word.Document
    Dim strWordDoc As String, strDefaultPrinter
    
    strWordDoc = Me.DocPath
    
    Set appWord = CreateObject("Word.Application")
    appWord.Documents.Open (strWordDoc)
    Set doc = appWord.ActiveDocument

    strDefaultPrinter = appWord.ActivePrinter
    appWord.ActivePrinter = "PDF995"
        
    doc.PrintOut
    Call Wait(6)
    appWord.ActivePrinter = strDefaultPrinter
    
    doc.Close
    appWord.Quit

Exit_PrintWordDoc:
        'clear object variables
    Set doc = Nothing
    Set appWord = Nothing
    Exit Function

Err_PrintWordDoc:
    MsgBox Err.Number & ", " & Err.Description, , "Error in Function PrintWordDoc of Module Module6"
    Resume Exit_PrintWordDoc

End Function

Open in new window

0
John_BASAuthor Commented:
Hi Omqanq,
Thanx for effort
I am trying your solution and i already see some signs of working.... :-)
I will let you know in few minutes...
0
John_BASAuthor Commented:
Thanx omqanq,
Its working fine...
0
John_BASAuthor Commented:
Solution was helpful...
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 Access

From novice to tech pro — start learning today.