Sudden Problem with a Word Merge file

J

Joe Cilinceon

I've been using a Word Merge file to print a Lease. It has worked fine in
the past and I've made no changes to it. The only thing I've have done clean
up the front end by the suggested method of opening a new db etc. I've done
this several times before and never had a problem. What is happening now is
it does the lease fine the first time but if I try to run it again it hangs.
If I close the programs and restart it will run fine again 1 time only. Any
one have a clue what could be doing this.
 
J

Joe Cilinceon

Ok, I have found what is doing it, now to fix it. I have a book mark in the
header of the document and that is what allows it to only print once. If I
rem it out it will print as many times as I like. Remove the rem and it only
prints once with out a restart of the program. What am I missing here. I've
added the basic code below (shortened for size here)

Private Sub MergeButton_Click()
On Error GoTo MergeButton_Err

Dim objWord As Word.Application

Set objWord = CreateObject("Word.Application")

With objWord
'Make the application visible.
.Visible = True

'Open the document.
.Documents.Open ("C:\Handi\Lease\Lease.doc")

'Move to each bookmark and insert text from the form.
ActiveDocument.Bookmarks("lease").Select ' this bookmark here is
the one that is in the header of the document
.Selection.Text = ([fsubTenantLeases].Form![LedgerID])
.ActiveDocument.Bookmarks("ax1").Select
.Selection.Text = (CStr(FORMS![frmTENANTS]![AccountName]))

(A Bunch more of these here just cut out for size sake)

End With

'Print the document in the foreground so Microsoft Word will not close
'until the document finishes printing.
objWord.ActiveDocument.PrintOut Background:=False

'Close the document without saving changes.
objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

'Quit Microsoft Word and release the object variable.
objWord.Quit
Set objWord = Nothing
Exit Sub

MergeButton_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If

Exit Sub
End Sub
 
Top