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.
'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.