Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 Mailshot from Access

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-12-27 : 11:43:39
writes "Hi,

I am able to email individuals from my access database but now I am wanting to create mailshots of 150+ people at one time. Please could you assist me in setting up the mailshot.

Regards,

Catherine Brink
Arrow Executive Search
+27 11 883 7117"

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2002-12-27 : 19:00:49
create a module with the following.


Option Compare Database
Option Explicit

Public Function ReadUntil(ByRef sIn As String, sDelim As String, Optional bCompare As Integer = vbBinaryCompare) As String
Dim nPos As String

nPos = InStr(1, sIn, sDelim, bCompare)

If nPos > 0 Then
ReadUntil = Left(sIn, nPos - 1)
sIn = Mid(sIn, nPos + Len(sDelim))
End If
End Function


Public Function Split(ByVal sIn As String, Optional sDelim As String, Optional nLimit As Long = -1, Optional bCompare As Integer = vbBinaryCompare) As Variant

Dim sRead As String, sOut() As String, nC As Integer
If sDelim = "" Then
Split = sIn
End If

sRead = ReadUntil(sIn, sDelim, bCompare)

Do
ReDim Preserve sOut(nC)
sOut(nC) = sRead
nC = nC + 1
If nLimit <> -1 And nC >= nLimit Then Exit Do
sRead = ReadUntil(sIn, sDelim)
Loop While sRead <> ""

ReDim Preserve sOut(nC)
sOut(nC) = sIn
Split = sOut
End Function



Public Function SendOutlookMail(ByVal strSubject As String, ByVal strBody As String, ByVal strRecipients As String, Optional ByVal strAttachments As String = "", Optional ByVal bolPreview As Boolean = False)
Dim golApp As Object
Dim objNewMail As Object
Dim Recipients As Variant
Dim Attachments As Variant
Dim i As Integer


Set golApp = CreateObject("Outlook.Application")
Set objNewMail = golApp.CreateItem(0)
objNewMail.Subject = strSubject
objNewMail.Body = strBody

Recipients = Split(strRecipients, ";")
For i = LBound(Recipients) To UBound(Recipients)
If Recipients(i) <> "" Then
objNewMail.Recipients.Add (Recipients(i))
End If
Next

If strAttachments <> "" Then
Attachments = Split(strAttachments, ";")

For i = LBound(Attachments) To UBound(Attachments)
If Attachments(i) <> "" Then
objNewMail.Attachments.Add (Attachments(i))
End If
Next

End If

If bolPreview = True Then
objNewMail.Display
Else
objNewMail.Send
End If

Set golApp = Nothing
Set objNewMail = Nothing

End Function


Now you can use the SendOutlookMail function to email multiple people.

All you have to do is pass in a string of Recipients separated by ;.
"Recipient1@abc.com;Recipient2@abc.com"
For Attachments you have to provide the file paths also separated by ;

Write a query that returns the names of the people loop over the data and create the recipient string.

Feel free to add in CC and BCC.

Enjoy




Edited by - ValterBorges on 12/28/2002 10:43:06
Go to Top of Page
   

- Advertisement -