Open Microsoft Word Document in Access

How would I go about setting up a a button in Access 2013 to open a certain word document and insert in information from access? Example is we have a label printer so I was going to set it up to get mailing information and print to that printer which I have done but sometimes we need to edit the mailing address so I would like to open a blank word document and edit from there unless there is a better solution. Thanks
Brandon GarnettAsked:
Who is Participating?
 
John TsioumprisSoftware & Systems EngineerCommented:
Try this for a start

Dim objWord As Object
Dim objDoc As Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add(ThePathToTheDocumentYourAreGoingToUseAsTemplate)
With objDoc
.formfields(NameOfTheFormField).result = TheValueYouWantToPass

End With
objWord.Selection.WholeStory
    objWord.Selection.Fields.Unlink
objDoc.PrintOut
    Set objDoc = Nothing
    Set objWord = Nothing

Open in new window

In order for this to work you need to use Form Fields
0
 
Fabrice LambertFabrice LambertCommented:
Hi,

easy enough:
public sub button1_onClick()
On Error Goto Error
    Dim app As Object    '// Word.Application
    Dim doc As Object    '// Word.Document

    Set app = createObject("Word.Document")
    set doc = app.Documents.Add    '// create an empty document
    app.Visible = True

    '// manipulate your document here

    doc.SaveAs2 "c:\.............."
    set doc = Nothing
    app.Quit False
    set app = Nothing
Exit Sub
Error:
    If Not(doc Is Nothing) Then
        doc.Close False
        Set doc = Nothing
    End If
    If Not(app Is Nothing) Then
        app.Quit False
        Set app = Nothing
    End If
End Sub

Open in new window

Note:
Do not close the document neither exit the application if you want to keep it open, just set the objects to Nothing.
0
 
Brandon GarnettAuthor Commented:
Thanks!
0
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.

All Courses

From novice to tech pro — start learning today.