A
Adrian
I have some code which, from an Access form, invokes Word in the
background,
opens a document, connects it to a mail merge file, and then merges the
result to email.
This worked happily in Office 2000 and 2002 / XP but no longer works in
2003. Outside of Access, Word will happily merge to email, so I know
the MIME connection
between Word and the email client is working OK. Any thoughts?
Code is as follows
Function doemail(strmergefile As String, strdatafile As String) As
Boolean
Dim wrd As Word.Application, IsRunning As Boolean, MyMerge As
Word.MailMerge
IsRunning = True
Set wrd = GetObject(, "Word.Application")
' Make word invisible
wrd.Visible = False
' Open the word file
On Error Resume Next
wrd.Documents.Open filename:=strmergefile
Set MyMerge = wrd.ActiveDocument.MailMerge
' Set the mail merge data and header sources
MyMerge.OpenDataSource _
strdatafile, _
ReadOnly:=False, LinkToSource:=True, _
Format:=wdOpenFormatAuto, _
Connection:="", SQLStatement:="", SQLStatement1:=""
' Execute the mail merge to email
With MyMerge
.Destination = wdSendToEmail
.MailAsAttachment = False
.MailAddressFieldName = "email"
.MailSubject = mesubjectline
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
If IsRunning = False Then 'If word was started, close it
wrd.Quit Word.wdDoNotSaveChanges
Else
wrd.ActiveDocument.close Word.wdDoNotSaveChanges
End If
Set wrd = Nothing
Set MyMerge = Nothing
Exit Function
Err_startword:
If Err.Number = 429 Then ' Word was not running
Set wrd = CreateObject("Word.Application")
IsRunning = False
Resume Next
Else
MsgBox Err.Number & " " & Err.Description
Exit Function
End If
End Function
background,
opens a document, connects it to a mail merge file, and then merges the
result to email.
This worked happily in Office 2000 and 2002 / XP but no longer works in
2003. Outside of Access, Word will happily merge to email, so I know
the MIME connection
between Word and the email client is working OK. Any thoughts?
Code is as follows
Function doemail(strmergefile As String, strdatafile As String) As
Boolean
Dim wrd As Word.Application, IsRunning As Boolean, MyMerge As
Word.MailMerge
IsRunning = True
Set wrd = GetObject(, "Word.Application")
' Make word invisible
wrd.Visible = False
' Open the word file
On Error Resume Next
wrd.Documents.Open filename:=strmergefile
Set MyMerge = wrd.ActiveDocument.MailMerge
' Set the mail merge data and header sources
MyMerge.OpenDataSource _
strdatafile, _
ReadOnly:=False, LinkToSource:=True, _
Format:=wdOpenFormatAuto, _
Connection:="", SQLStatement:="", SQLStatement1:=""
' Execute the mail merge to email
With MyMerge
.Destination = wdSendToEmail
.MailAsAttachment = False
.MailAddressFieldName = "email"
.MailSubject = mesubjectline
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
If IsRunning = False Then 'If word was started, close it
wrd.Quit Word.wdDoNotSaveChanges
Else
wrd.ActiveDocument.close Word.wdDoNotSaveChanges
End If
Set wrd = Nothing
Set MyMerge = Nothing
Exit Function
Err_startword:
If Err.Number = 429 Then ' Word was not running
Set wrd = CreateObject("Word.Application")
IsRunning = False
Resume Next
Else
MsgBox Err.Number & " " & Err.Description
Exit Function
End If
End Function