Hello I am using access to fill out a word document using Bookmarks, the code work but the problem that I can use this just one time, if I run the code twice I always get this error:
Run Time error '462': the remote server machine does not exist or is unavailable
is there nay way to avoid this?
this is the code I am using:
Private Sub Command320_Click()
Dim LWordDoc As String
Dim oApp As Object
'Path to the word document
LWordDoc = "C:\Users\temp\Documents\Contractor DB\contrato.dotx"
If Dir(LWordDoc) = "" Then
MsgBox "Document not found."
Else
'Create an instance of MS Word
Set oApp = CreateObject(Class:="Word.Application")
oApp.Visible = True
'Open the Document
oApp.Documents.Open Filename:=LWordDoc
End If
Dim Name As Word.Range
Set Name = ActiveDocument.Bookmarks("name").Range
Name.Text = [Form]![Name]
Dim LastName As Word.Range
Set Name = ActiveDocument.Bookmarks("lastname").Range
Name.Text = [Form]![Last Name]
Dim Company As Word.Range
Set Name = ActiveDocument.Bookmarks("company").Range
Name.Text = [Form]![Company]
Dim Address As Word.Range
Set Name = ActiveDocument.Bookmarks("Address").Range
Name.Text = [Form]![FullAddress]
Dim Nombre As Word.Range
Set Name = ActiveDocument.Bookmarks("nombre").Range
Name.Text = [Form]![Name]
Dim APELLIDO As Word.Range
Set Name = ActiveDocument.Bookmarks("APELLIDO").Range
Name.Text = [Form]![Last Name]
Dim lastnamerate As Word.Range
Set Name = ActiveDocument.Bookmarks("lastnamerate").Range
Name.Text = [Form]![Last Name]
Dim firstnamerate As Word.Range
Set Name = ActiveDocument.Bookmarks("firstnamerate").Range
Name.Text = [Form]![Name]
Dim mnamerate As Word.Range
Set Name = ActiveDocument.Bookmarks("mnamerate").Range
Name.Text = [Form]![Middle Name]
End Sub
Thanks