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!

Creating Word Documents from Access

Status
Not open for further replies.

dpimental

Programmer
Jul 23, 2002
535
US
How do you create MSWord Documents from an access database?

I have data in several tables, some constant (will always be applied) and some variable (will change each time I construct a document).

David David Pimental
(US, Oh)
dpimental@checkfree.com
 
David,

Although I've just started messing with Word automation, I've been able to create word documents from Access forms using the following code:

I used the following to pass just the form's current record to word using an On Click event.

Dim objWord As Word.Application

'Start Microsoft Word
Set objWord = createObject("Word.Application")

With objWord
'Make Word visible
.Visible = True

'Open the document
.Documents.Open ("C:\MyMerge.dot")

'Move to the bookmark and insert text from the form
.ActiveDocument.Bookmarks("First").Select
.Selection.Text = (CStr(Forms!Employees!FirstName))

End With

Hope this helps.
Bill
 
How do you just create the document, write to it (keep it invisible) and then save it?

David David Pimental
(US, Oh)
dpimental@checkfree.com
 
You need to make a template in Word, and then place Bookmarks into the Word doc (Insert, Bookmark). Give the bookmark a meaningful name (Like FirstName) and then you save it.

In Access, reference the word bookmark in code like:
.ActiveDocument.Bookmarks("FirstName").Select

Then put the date from your form into the word bookmark by using this code:

.Selection.Text = (Forms!YourFormName!YourFieldName)

That should do it.

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top