Opening a Word template using a button on a form

  • Thread starter Thread starter Polly
  • Start date Start date
P

Polly

Hi,

I have a basic-intermediate knowledge of Access 2000 (I've learnt i
all myself, and do fine until I run up against jargon - someone shoul
create a translation dictionary I think).

I need to know if there is any way of opening a Word template using
command button on a form in Access 2000?

For example what I would like to happen is: I want to send a letter t
someone, so I view their details on the contact form, then press th
button and presto, Word opens in letter template with their addres
details and opening line (Dear...) inserted (ok, that's a little mor
than just opening the file, but I can hope)

Please someone help! I've worked out how to make Word run using th
RunApp macro, but even after looking through my massive arm breakin
manual I can't work it out. It's probably something to do with visua
basic I expect, but I'm still a little lost in the woods with workin
that lot out.

Thank you
 
create a control button (my button was cmdFollowlink)

dim hlk as hyperlink

Set hlk = [cmdFollowLink].Hyperlink
With hlk
.Address = Me![txtaddress]

.Follow
End With

ME!txtaddress is a text box on my form that contains the name and pat
of the word document to be opened.

You can set this based on a button being clicked (onclick event) or b
any other event on the form. (I used a button because it is one of th
controls types that allow a hyperlink to be attached to the object)
 
Here is another method

Public Function CreateDoc()
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Dim strLetter As String
Dim strConnect As String

' Create an instance of Microsoft Word 97.
Set WordApp = CreateObject("Word.Application")

' Create a new, empty document.
Set WordDoc = WordApp.Documents.Add
strLetter = "Thank you for your business during the pas
year."
With WordApp.Selection
.TypeParagraph
.TypeParagraph
.TypeText Text:=strLetter
.TypeParagraph
.TypeParagraph
.TypeText Text:="Sincerely,"
.TypeParagraph
.TypeParagraph
.TypeText Text:="Northwind Traders"
End With

WordApp.Visible = True
End Function


This opens a word document that is independant of Access, however yo
can add text to the document in between the .Add and the end of th
function.

In addition you could have opened a named word document that alread
exists.
Set WordDoc = WordApp.Documents.Open(FileName)
For this to work you must include Your current word reference librar
in your library references, otherwise it won't find some of th
references and type
 
Back
Top