R
ref
I am running a Mail Merge initiated from a DTS package using Visual Basic
ActiveX
The word document for the mail merge uses a datasource (.odc file) against
a sql server 2000 database.
Now if I run the mailmerge from the directory where the word doc and .odc
file reside, it works fine. If I run the DTS package that invokes the below
script locally it also runs fine, however it fails when it runs as a
scheduled job at the statement .Destination = wdSendToNewDocument in the
script below. I suspect it's an issue with referencing that datasouce. Can
someone suggest the code I would need to establish the database connection
and sql statement within the below script versus relying on the connection to
the .odc file
Thanks in advance
'************************************************************' Visual Basic
ActiveX Script
'************************************************************Function Main()
Dim WordFileTemplateName
Dim WordFileOutputName
Dim appword
WordFileTemplateName = "\\xyz\MailMerge\Hold\BillMM.doc"
WordFileOutputName = "\\xyz\MailMerge\Hold\Billout.doc"
Set appword = CreateObject("word.application")
appword.Visible = False
appword.Documents.Open WordFileTemplateName
With appword.ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
.Execute Pause=True
End With
With appword.ActiveDocument
.SaveAs(WordFileOutputName)
End With
appword.Quit (False) 'without saving
set appword = nothing
Main = DTSTaskExecResult_Success
End Function
ActiveX
The word document for the mail merge uses a datasource (.odc file) against
a sql server 2000 database.
Now if I run the mailmerge from the directory where the word doc and .odc
file reside, it works fine. If I run the DTS package that invokes the below
script locally it also runs fine, however it fails when it runs as a
scheduled job at the statement .Destination = wdSendToNewDocument in the
script below. I suspect it's an issue with referencing that datasouce. Can
someone suggest the code I would need to establish the database connection
and sql statement within the below script versus relying on the connection to
the .odc file
Thanks in advance
'************************************************************' Visual Basic
ActiveX Script
'************************************************************Function Main()
Dim WordFileTemplateName
Dim WordFileOutputName
Dim appword
WordFileTemplateName = "\\xyz\MailMerge\Hold\BillMM.doc"
WordFileOutputName = "\\xyz\MailMerge\Hold\Billout.doc"
Set appword = CreateObject("word.application")
appword.Visible = False
appword.Documents.Open WordFileTemplateName
With appword.ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
.Execute Pause=True
End With
With appword.ActiveDocument
.SaveAs(WordFileOutputName)
End With
appword.Quit (False) 'without saving
set appword = nothing
Main = DTSTaskExecResult_Success
End Function