Create Word document from a single Access record

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
Back
Top