Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word output from within access 1

Status
Not open for further replies.

eocheng

Technical User
Apr 28, 2004
13
CA
Hi,

I'm looking for a guidance/examples on how to format a word document using VBA.

ie.
1. how to add a header/footer
2. how to add a carriage return between fields
3. how to add an image

currently, I have it set up to write all the data to a string and then output the string using the typetext strOutput property.

Any comments/help are greatly appreciated. Thank you kindly.

e
 
If you have access to the Access Developer's Handbook, Chapter 12 gives a very good example of how to do this using Word bookmarks.

Basically, open a word document using an existing template with the bookmarks established, then export the data from Access to each individual bookmark, then save the document using whatever name.

Code:
    Set objWord = New Word.Application
    objWord.Visible = True
    Set objWordDoc = objWord.Documents.Add(Template:="MyTemplate.dot", NewTemplate:=False)
    With objWordDoc.Bookmarks
        .Item("FirstField").Range.Text = Me.MyField
        .Item("SecondField").Range.Text = Me.MySecondField
    End With

'Save a backup copy of the letter to the backup folder
    objWord.ActiveDocument.SaveAs FileName:="C:\MyPath\" & [MyDocName.doc"

HTH
Lightning
 
Hi Lightning,

Can always count on lightning providing lightning fast results! It worked perfectly!

Thank you for your time and help. It is greatly appreciated!

e
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top