Run time Error 5151 was unable to read this document (1 Viewer)

feprice

New member
Local time
Today, 03:25
Joined
Oct 12, 2014
Messages
2
I have entered the following code from Access Book. When it gets to the portion where it should open word doc Comment 'Problem area. I receive the error message Run time error '5151' was unable to read this document.

Private Sub Merge_to_Word_Letter_Click()

Dim AddyLineVar, SalutationVar As String

If IsNull([LastName]) Then
AddyLineVar = [Company]
SalutationVar = "Sirs"
Else
AddyLineVar = [FirstName] + " " + [LastName]
If Not IsNull([Company]) Then
AddyLineVar = AddyLineVar + vbCrLf + [Company]
End If

SalutationVar = [FirstName]
End If

AddyLineVar = AddyLineVar + vbCrLf + [Address1]

If Not IsNull([Address2]) Then
AddyLineVar = AddyLineVar + vbCrLf + [Address2]
End If

AddyLineVar = AddyLineVar + vbCrLf + [City] + " "
AddyLineVar = AddyLineVar + [State] + " " + [Zip]

Dim Word As New Word.Application
Set Word = CreateObject("Word.Application")

Dim Merge As String
MergeDoc = Application.CurrentProject.Path
MergeDoc = MergeDoc + "\WordFormLetter.dot"
'Problem Area
Word.Documents.Add MergeDoc
'Word.Documents.Add "C:\Documents and Settings\My Documents\WordFormLetter.dot"
'Word.Documents.Open MergeDoc
Word.Visible = True

With Word.ActiveDocument.Bookmarks
.Item("TodaysDate").Range.Text = Date
.Item("AddressLines").Range.Text = AddyLineVar
.Item("Salutation").Range.Text = SalutationVar
End With

Word.ActiveDocument.Close wdDoNotSaveChanges
Word.Quit
End Sub
 

Users who are viewing this thread

Top Bottom