Problem with Normal.dot

T

Thronz

I have an MSAccess database which calls up a Word document and populates Form
fields with data from the current record. This all works fine. My problems is
that Word is now running (I released it in VBA coding) and when I try to
close it down, I am asked if I want to saved the changes to Normal.dot. Once
I get rid of the pop-ups and close Word down, I then get messages that I
already have Normal.dot running??

Here is the code from the database:

Private Sub Printform_Click()
On Error GoTo Err_Printform_Click
Dim wrdApp As Word.Application
Dim doc As String
Dim locat As String
Dim fs
Set wrdApp = New Word.Application
Set fs = CreateObject("Scripting.FileSystemObject")

doc = "N:\Security\Reception\Forms\Contractor Renewal Form.doc"
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")
End Sub


Thanks in advance for your time and help
 
J

Jezebel

Before quitting, tell Word that normal.dot doesn't need saving:

wrdApp.NormalTemplate.Saved = true


Separately, your code's use of ActiveDocument is risky: the document is
actually a property of the Word application object. Currently you're relying
on VB to resolve the unqualified reference. Safer is --

Dim pDoc as Word.Document
:
set pDoc = wrdApp.Documents.Open (filename:=doc)
pDoc.FormFields("Name").Result = ...
 
T

Thronz

Thanks for the help on the Normal template. It's working fine in the printing
and closing of the document. But, there are still bugs!!!!
The problem now is that any subsequent attempts at running the macro (print
a record) causes the error: "THE REMOTE SERVER MACHINE DOES NOT EXIST OR IS
UNAVAILABLE". If I close down the database and restart it, the macro runs
without bugging out. I am thinking this is an Access issue and will post
there.
I am attaching the new code for anyone who might have a similar project.

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


Thanks for your time and help, this is GREAT resource!
 

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

Top