M
mike
Hi all
I'm trying to use the following code, to retrieve data from "name" time
and place text boxs on a form ,into respective bookmarks on a word
template file (WordFormLetter.dot).
When I run the code, word application opens, a printout comes out but
without the data to be reterieved.
Please help
Thanks in advance
Mike
Private Sub Command6_Click()
'Declare variables for storing string(text)
Dim name, time, place As String
name = [name]
time = [time]
place = [place]
'Declare an instance of Microsoft Word.
Dim Wrd As New Word.Application
Set Wrd = CreateObject("Word.Application")
'Specify the path and name to the word document
Dim MergeDoc As String
MergeDoc = Application.CurrentProject.Path
MergeDoc = MergeDoc + "\WordFormLetter.dot"
'Open the document template and make it visible
Wrd.Documents.Add MergeDoc
Wrd.Visible = True
'Replace each bookmark with current data
With Wrd.ActiveDocument.Bookmarks
.Item("name").Range.Text = name
.Item("time").Range.Text = time
.Item("place").Range.Text = Range
End With
'Document is ready to print
Wrd.ActiveDocument.PrintOut
'Close the document without saving
Wrd.ActiveDocument.Close wdDoNotSaveChanges
Wrd.Quit
End Sub
I'm trying to use the following code, to retrieve data from "name" time
and place text boxs on a form ,into respective bookmarks on a word
template file (WordFormLetter.dot).
When I run the code, word application opens, a printout comes out but
without the data to be reterieved.
Please help
Thanks in advance
Mike
Private Sub Command6_Click()
'Declare variables for storing string(text)
Dim name, time, place As String
name = [name]
time = [time]
place = [place]
'Declare an instance of Microsoft Word.
Dim Wrd As New Word.Application
Set Wrd = CreateObject("Word.Application")
'Specify the path and name to the word document
Dim MergeDoc As String
MergeDoc = Application.CurrentProject.Path
MergeDoc = MergeDoc + "\WordFormLetter.dot"
'Open the document template and make it visible
Wrd.Documents.Add MergeDoc
Wrd.Visible = True
'Replace each bookmark with current data
With Wrd.ActiveDocument.Bookmarks
.Item("name").Range.Text = name
.Item("time").Range.Text = time
.Item("place").Range.Text = Range
End With
'Document is ready to print
Wrd.ActiveDocument.PrintOut
'Close the document without saving
Wrd.ActiveDocument.Close wdDoNotSaveChanges
Wrd.Quit
End Sub