Create Word document from a single Access record

G

Guest

I have a database with thousands of contacts. I need to be able to create a
Word document based an exiting Word template from data found on the Access
form on the screen. The Access screen contains information about only one
contact...FirstName, LastName, CompanyName, etc.

My hope is to have a button that says "Create Fax" behind which is VBA code
that would open a new Word document, name it, import relevant data, save it
to a designated location, and then allow the user to type whatever they want.

Does anyone have any idea how to do this? I am very familiar with VBA
programming in Access, but have never yet done anything with any applications
outside Access. I have searched on this board and seen lots of info
regarding mail merging, but that isn't exactly what I want to do since I need
only data from a single record.

Thanks to anyone that can point me in the right direction!!

Brian
 
J

John Nurick

Hi Brian,

Actually, mail merge may be the simplest solution. You can do it with a
single record. Go to
http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html and
scroll down until you find Super Easy Word Merge.

Or you can do it like this:

1) put bookmarks in the Word template where each bit of information
should go

2) In the Access VBA project, set a reference to the Microsoft Word
object library and write code along these lines (I'll leave you to fill
in the details)

Dim oWord As Word.Application
Dim oDoc As Word.Document

Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Add("D:\Folder\Template.dot")

'control oWord.Visible and oDoc.Windows(1).Visible if necessary

With oDoc
.Bookmarks("FirstName").Range.Text = _
Me.Controls("txtFirstName").Value
...
.SaveAs "D:\Folder\Filename.doc"
.Close
End With

oWord.Quit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top