Word Won't Close After Merge (1 Viewer)

rtdc

Registered User.
Local time
Today, 16:41
Joined
Feb 27, 2007
Messages
55
I found a nice piece of Code in the forum to send data to word and populate form fields rather than using mail merging with an exported text file. It works great but the problem I have is Word stays open after the job is complete. I have told it to save as the finished document which it does and word does not show open in the applications list but is open in process window, my code is

'REQUIRE MICROSOFT WORD 11 OBJECT LIBARY

Dim objWord As Word.Application
Dim wrdDoc As Word.Document
Dim strPath As String

strPath = "C:\SFL00001\SFL00001_Summary.doc"
Set objWord = New Word.Application
With objWord
.Visible = False
.WindowState = wdWindowStateMinimize
End With
Set wrdDoc = objWord.Documents.Open(strPath, , False, False, , , , , , , , True)

wrdDoc.FormFields("ReportNumber").Result = Nz(Forms!frmInvestigation.[ID_Field], "")
wrdDoc.FormFields("ReportedBy").Result = Nz(Forms!frmInvestigation.[ReportedBy], "")
wrdDoc.FormFields("CompleteBy").Result = Nz(Forms!frmInvestigation.[InvTargetDate], "")
wrdDoc.FormFields("ActualCompleted").Result = Nz(Forms!frmInvestigation.[DateInvComplete], "")

wrdDoc.SaveAs ("C:\SFL00001\SFL00001_Summary1.doc")
wrdDoc.Close (True)
Set objWord = Nothing

Can anyone think of a command to force Word to close?

Cheers.
 

chergh

blah
Local time
Today, 16:41
Joined
Jun 15, 2004
Messages
1,414
objWord.quit
 

rtdc

Registered User.
Local time
Today, 16:41
Joined
Feb 27, 2007
Messages
55
Tried that thanks but it comes back with

Expected Function or Variable
 

chergh

blah
Local time
Today, 16:41
Joined
Jun 15, 2004
Messages
1,414
It is the correct method to use, and it works as expected in all my apps, no idea why it is returning that error for you though.
 

rtdc

Registered User.
Local time
Today, 16:41
Joined
Feb 27, 2007
Messages
55
Got it working, needed

objWord.Quit
Set objWord = Nothing

simple in the end got the sequence the wrong way round.

See ya.
:)
 

Users who are viewing this thread

Top Bottom