From: Mike on
Hi,
I have a word template which in autonew makes a mail merge and sends e-mail.
This have worked fine but now one of my customers have updated to windows7
and office 2007 and suddenly no mail is sent. I have other customers running
XP and office 2007 were it works fine. But for this client the question from
outlook is raised asking if its OK to send mail from an other application but
no mail is sent.
The code:

Sub Autonew()
Dim SQL_sats As String
Registry_Path = "HKEY_CURRENT_USER\Software\The company\Directories"
Registry_Key = "CustDocs"

Found_Path = System.PrivateProfileString(FileName:="", _
Section:=Registry_Path, Key:=Registry_Key)
If Found_Path = "" Then
Found_Path = "c:\temp\"
End If
SQL_sats = "Select * from " & Found_Path & "multistatement.txt" & "
where ((CUSTOMER_EMAIL IS NOT NULL))"
On Error GoTo PostPrint
ActiveDocument.MailMerge.DataSource.QueryString = SQL_sats
With ActiveDocument
.AttachedTemplate = ""
.SaveAs "Statement.doc", wdFormatDocument
With ActiveDocument.MailMerge
.Destination = wdSendToEmail
.MailAsAttachment = True
.MailAddressFieldName = "CUSTOMER_EMAIL"
.MailSubject = "Statement"
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
PostPrint:
On Error GoTo 0
SQL_sats = "Select * from " & Found_Path & "multistatement.txt" & " where
((CUSTOMER_EMAIL IS NULL ))"
On Error GoTo Comple
ActiveDocument.MailMerge.DataSource.QueryString = SQL_sats
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
Comple:
End With
End Sub