T
Thronz
My problem is that the coding (below) I have to print a document (from a
template) based on the current record (MSAccess Form) works fine for the
first instance, but after that I get an error message of "THE REMOTE SERVER
MACHINE DOES NOT EXIST OR IS UNAVAILABLE". If I restart the database the
document will print but I get the same error when I try to print any others.
The code is:
Private Sub Printform_Click()
Dim doc As String
Dim locat As String
Dim wrdApp As Word.Application
Dim fs As Object
Dim pDoc As Word.Document
Set fs = CreateObject("Scripting.FileSystemObject")
Set wrdApp = New Word.Application
Set pDoc =
wrdApp.Documents.Open(filename:="N:\Security\Reception\Forms\Contractor
Renewal Form.doc")
On Error GoTo Err_Printform_Click
locat = "N:\Security\Reception\Contractors" & "\" & Me.ID & ".jpg"
If fs.FileExists(locat) = False Then locat =
"N:\Security\Reception\Contractors\NoPix.JPG"
wrdApp.Visible = False
pDoc.FormFields("Name").Result = Lastname + ", " + Me.Given1 + " " &
Me.Given2
pDoc.FormFields("Address").Result = Me.Address & " " & Me.City
pDoc.FormFields("ID").Result = Me.ID
pDoc.FormFields("DOB").Result = Me.DOB
pDoc.FormFields("Employer").Result = Me.Employer
pDoc.FormFields("Reason").Result = Me.ReasonforAccess
pDoc.FormFields("Contact").Result = Contact
pDoc.Bookmarks("Photo").Select
Selection.InlineShapes.AddPicture filename:=locat
Options.PrintBackground = False
pDoc.PrintOut
pDoc.ResetFormFields
wrdApp.Documents.Close saveChanges:=wdDoNotSaveChanges
wrdApp.NormalTemplate.Saved = True
wrdApp.Quit
Set wrdApp = Nothing
Set pDoc = Nothing
GoTo 100
Err_Printform_Click:
MsgBox (Error)
pDoc.ResetFormFields
wrdApp.Documents.Close saveChanges:=wdDoNotSaveChanges
wrdApp.NormalTemplate.Saved = True
wrdApp.Quit
Set wrdApp = Nothing
Set pDoc = Nothing
100
End Sub
template) based on the current record (MSAccess Form) works fine for the
first instance, but after that I get an error message of "THE REMOTE SERVER
MACHINE DOES NOT EXIST OR IS UNAVAILABLE". If I restart the database the
document will print but I get the same error when I try to print any others.
The code is:
Private Sub Printform_Click()
Dim doc As String
Dim locat As String
Dim wrdApp As Word.Application
Dim fs As Object
Dim pDoc As Word.Document
Set fs = CreateObject("Scripting.FileSystemObject")
Set wrdApp = New Word.Application
Set pDoc =
wrdApp.Documents.Open(filename:="N:\Security\Reception\Forms\Contractor
Renewal Form.doc")
On Error GoTo Err_Printform_Click
locat = "N:\Security\Reception\Contractors" & "\" & Me.ID & ".jpg"
If fs.FileExists(locat) = False Then locat =
"N:\Security\Reception\Contractors\NoPix.JPG"
wrdApp.Visible = False
pDoc.FormFields("Name").Result = Lastname + ", " + Me.Given1 + " " &
Me.Given2
pDoc.FormFields("Address").Result = Me.Address & " " & Me.City
pDoc.FormFields("ID").Result = Me.ID
pDoc.FormFields("DOB").Result = Me.DOB
pDoc.FormFields("Employer").Result = Me.Employer
pDoc.FormFields("Reason").Result = Me.ReasonforAccess
pDoc.FormFields("Contact").Result = Contact
pDoc.Bookmarks("Photo").Select
Selection.InlineShapes.AddPicture filename:=locat
Options.PrintBackground = False
pDoc.PrintOut
pDoc.ResetFormFields
wrdApp.Documents.Close saveChanges:=wdDoNotSaveChanges
wrdApp.NormalTemplate.Saved = True
wrdApp.Quit
Set wrdApp = Nothing
Set pDoc = Nothing
GoTo 100
Err_Printform_Click:
MsgBox (Error)
pDoc.ResetFormFields
wrdApp.Documents.Close saveChanges:=wdDoNotSaveChanges
wrdApp.NormalTemplate.Saved = True
wrdApp.Quit
Set wrdApp = Nothing
Set pDoc = Nothing
100
End Sub