Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-time error 462

Status
Not open for further replies.

mgmslate

Technical User
Feb 18, 2002
24
0
0
US
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
 
Was the word document created by the fact you ran this the first time and it doen't UPDATE the file thereafter? If so, maybe you can edit your code to add something different to the document name each time:

[tt] With objdoc
.Documents.Add Template:=("c:\inventory database\"& str(Date()) & "-intro.doc"), NewTemplate:=False, DocumentType:=0
.Visible = True

Didn't try this, but if the answer to my question is YES, this should solve your problem, as long as you don't do this more than once per day.


Jim DeGeorge [wavey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top