A
Adrian
Hello
I had a nice bit of code in Access 2002 which opened Word 2002, opened
a mail merge document and merged it to email. This meant that one could
email from Access, via Word without needing Outlook, which some of my
users did not like.
It does not work in Access 2003 and I can't see why. Any thoughts much
appreciated. ( I have checked the MIME connection between Word and
email client and that's OK)
Cheers
Adrian
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
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
End Function
I had a nice bit of code in Access 2002 which opened Word 2002, opened
a mail merge document and merged it to email. This meant that one could
email from Access, via Word without needing Outlook, which some of my
users did not like.
It does not work in Access 2003 and I can't see why. Any thoughts much
appreciated. ( I have checked the MIME connection between Word and
email client and that's OK)
Cheers
Adrian
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
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
End Function