open word document

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
Set wrdApp = New Word.Application
Set fs = CreateObject("Scripting.FileSystemObject")
On Error GoTo Err_Printform_Click

doc = "N:\Security\Reception\Forms\Contractor Renewal Form.dot"
locat = "N:\Security\Reception\Contractors" & "\" & Me.ID & ".jpg"
If fs.FileExists(locat) = False Then locat =
"N:\Security\Reception\Contractors\NoPix.JPG"

wrdApp.Documents.Open filename:=doc
wrdApp.Visible = False

ActiveDocument.FormFields("Name").Result = Lastname + ", " + Me.Given1 + " "
& Me.Given2
ActiveDocument.FormFields("Address").Result = Me.Address & " " & Me.City
ActiveDocument.FormFields("ID").Result = Me.ID
ActiveDocument.FormFields("DOB").Result = Me.DOB
ActiveDocument.FormFields("Employer").Result = Me.Employer
ActiveDocument.FormFields("Reason").Result = Me.ReasonforAccess
ActiveDocument.FormFields("Contact").Result = Contact
ActiveDocument.Bookmarks("Photo").Select
Selection.InlineShapes.AddPicture filename:=locat
Options.PrintBackground = False

ActiveDocument.PrintOut
wrdApp.Documents.Close saveChanges:=wdDoNotSaveChanges

wrdApp.Quit
Set wrdApp = Nothing
Exit Sub

Err_Printform_Click:
MsgBox (Error)
wrdApp.Quit
Set wrdApp = Nothing


End Sub


Any help is greatly appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top