PhredBear said:
Hi there,
I would like to use Outlook to send out a newsletter using the email
addresses from a MySQL table or an Access 2003 table(via ODBC from MySQL)
directly from my Membership Database. Can someone point me in the right
direction where I can make a start. I can't find anything usable on
Google or any relevent forums.
This sends mail from Access 2010 via Outlook 2010.
The code is very simple and I think it will run on
Office 2003 | 2007 as well.
I can check it if you have problems with your Office version.
========================================
Private Sub Command0_Click()
' References:
' Visual Basic for Applications
' Microsoft Outlook 14.0 Object Library
' Microsoft Office 14.0 Object Library
' Microsoft Office 14.0 Access database engine Object Library
' Microsoft Scripting Runtime
'
Dim NewMail As MailItem, S As String, i As Integer
Dim AttachmentArray(1 To 3) As String
Dim FSO As Object, TextStream As Object
Dim db As Database, RS As Recordset
Set db = CurrentDb
Set RS = db.OpenRecordset("t_Contacts", dbOpenDynaset)
' Table t_Contacts has 3 Fields:
' CompanyName, Attn, EmailAddress. All the Fields are Text(255).
' Some Attachments
AttachmentArray(1) = "C:\aa2.txt"
AttachmentArray(2) = "C:\aa3.txt"
AttachmentArray(3) = "C:\aa4.txt"
' C:\aa1.txt is your newsletter
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TextStream = FSO.OpenTextFile("C:\aa1.txt")
Do Until TextStream.AtEndOfStream
S = TextStream.ReadLine
Loop
Do Until RS.EOF
Set NewMail =
CreateObject("Outlook.Application").CreateItem(olMailItem)
With NewMail
.To = RS![eMailAddress] ' "aaaaa@aaa; bbbbb@bbb; ccccc@ccc"
'.CC = "ddddd@ddd; eeeee@eee"
'.BCC = "fffff@fff; ggggg@ggg"
.Subject = "My Special Subject"
.Body = RS![CompanyName] & vbCrLf & "Attn " & RS![Attn] & vbCrLf &
S
For i = 1 To 3
.Attachments.Add AttachmentArray(i)
Next
.Send
End With
Set NewMail = Nothing
RS.MoveNext
Loop
End Sub
=================================
Bruno