I am trying to export customer info from a form to bookmarks in a word doc. The first time it works fine, the next time I
get run-time error 462 the remote server machine does not exist or is unavailable and the template opens with no info in the bookmarks. After I close the document and end out of the debug it will work again.
Private Sub BtnIntro_Click()
Dim objdoc As Word.Application
Dim strstate As String
strstate = DLookup("[stateinitials]", "[state]", "stateid = " & Forms!customercenter!CustomerState)
Set objdoc = CreateObject("Word.Application"
With objdoc
.Documents.Add Template:=("c:\inventory database\intro.doc", NewTemplate:=False, DocumentType:=0
.Visible = True
.ActiveDocument.Bookmarks("firstname".Select
Selection.Text = (Forms!customercenter!ContactName)
.ActiveDocument.Bookmarks("company".Select
Selection.Text = (Forms!customercenter!CompanyName)
.ActiveDocument.Bookmarks("address".Select
Selection.Text = (Forms!customercenter!CustomerAddress1)
.ActiveDocument.Bookmarks("state".Select
Selection.Text = (strstate)
.ActiveDocument.Bookmarks("city".Select
Selection.Text = (Forms!customercenter!City)
.ActiveDocument.Bookmarks("zip".Select
Selection.Text = (Forms!customercenter!CustomerZip)
.ActiveDocument.Bookmarks("name".Select
Selection.Text = (Forms!customercenter!ContactName)
.WindowState = wdWindowStateMaximize
.Activate
'Print the Word Document and Close Word
.Options.PrintBackground = False ' No background Printing
.Application.DisplayAlerts = wdAlertsNone
.ActiveDocument.PrintOut 'Prints the Word Doc
'Close the Document without saving changes
.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
.Quit
End With
Set objdoc = Nothing
End Sub
Mike
get run-time error 462 the remote server machine does not exist or is unavailable and the template opens with no info in the bookmarks. After I close the document and end out of the debug it will work again.
Private Sub BtnIntro_Click()
Dim objdoc As Word.Application
Dim strstate As String
strstate = DLookup("[stateinitials]", "[state]", "stateid = " & Forms!customercenter!CustomerState)
Set objdoc = CreateObject("Word.Application"
With objdoc
.Documents.Add Template:=("c:\inventory database\intro.doc", NewTemplate:=False, DocumentType:=0
.Visible = True
.ActiveDocument.Bookmarks("firstname".Select
Selection.Text = (Forms!customercenter!ContactName)
.ActiveDocument.Bookmarks("company".Select
Selection.Text = (Forms!customercenter!CompanyName)
.ActiveDocument.Bookmarks("address".Select
Selection.Text = (Forms!customercenter!CustomerAddress1)
.ActiveDocument.Bookmarks("state".Select
Selection.Text = (strstate)
.ActiveDocument.Bookmarks("city".Select
Selection.Text = (Forms!customercenter!City)
.ActiveDocument.Bookmarks("zip".Select
Selection.Text = (Forms!customercenter!CustomerZip)
.ActiveDocument.Bookmarks("name".Select
Selection.Text = (Forms!customercenter!ContactName)
.WindowState = wdWindowStateMaximize
.Activate
'Print the Word Document and Close Word
.Options.PrintBackground = False ' No background Printing
.Application.DisplayAlerts = wdAlertsNone
.ActiveDocument.PrintOut 'Prints the Word Doc
'Close the Document without saving changes
.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
.Quit
End With
Set objdoc = Nothing
End Sub
Mike