I
Ivan Grozney
I am trying it get the following code in Access to call Outlook and send a
bunch of emails. Each one is different for each of the recipients and it can
be for one to 50 or even more. I would like to bypass the Outlook security,
preferably not using on of the 3rd party products like ClickYes.
I am using Outlook and Access 2003.
I have looked at other posts and at http://www.outlookcode.com/d/sec.htm
but I just don't get it.
TIA
Vanya
******* Start Record Set Code **************************************
Private Sub cmdMailTotalPoints_Click()
On Error GoTo Err_CmdMailTotalPoints_Click
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT <stuff> FROM <mytable>")
Set qdf = dbs.QueryDefs("<myQuery>")
BaseSQL = qdf.SQL
strFrom = "<whofrom>"
strSubject = "<Subject>"
strBodyEnd = vbCrLf & _
"If you have any questions..." & vbCrLf & _
vbCrLf & _
"Thank you ..."
With rst
Do Until .EOF
strSQL = Left(BaseSQL, Len(BaseSQL) - 1)
qdf.SQL = strSQL
strEmail = !HWorkEmail
strBodyStart = "" & !FirstName & ", " & vbCrLf & _
vbCrLf & _
"Your current account info is..." & vbCrLf & _
Stuff... vbCrLf
strBody = strBodyStart & strBodyEnd
' Call the Mass Mailing Routine
Call MassMail(strFrom, strBody, strEmail, strSubject)
.MoveNext
Loop
.Close
End With
qdf.SQL = BaseSQL
Set qdf = Nothing
Set rst = Nothing
Set dbs = Nothing
******* End Record Set Code **************************************
******** START OUTLOOK CODE ************************************
Private Sub MassMail(strFrom As Variant, strBody As Variant, strEmail As
Variant, strSubject As Variant)
Dim olApp As Outlook.Application
Dim olMsg As MailItem
Set olApp = CreateObject("Outlook.Application")
Set olMsg = outApp.CreateItem(olMailItem)
With olMsg
.To = strEmail
.SentOnBehalfOfName = strFrom
.Subject = "TEST TEST Please Delete TEST"
.SenderEmailAddress = strFrom
.Body = strBody
.Send
End With
Set olApp = Nothing
Set olMsg = Nothing
End Sub
******** END OUTLOOK CODE ************************************
bunch of emails. Each one is different for each of the recipients and it can
be for one to 50 or even more. I would like to bypass the Outlook security,
preferably not using on of the 3rd party products like ClickYes.
I am using Outlook and Access 2003.
I have looked at other posts and at http://www.outlookcode.com/d/sec.htm
but I just don't get it.
TIA
Vanya
******* Start Record Set Code **************************************
Private Sub cmdMailTotalPoints_Click()
On Error GoTo Err_CmdMailTotalPoints_Click
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT <stuff> FROM <mytable>")
Set qdf = dbs.QueryDefs("<myQuery>")
BaseSQL = qdf.SQL
strFrom = "<whofrom>"
strSubject = "<Subject>"
strBodyEnd = vbCrLf & _
"If you have any questions..." & vbCrLf & _
vbCrLf & _
"Thank you ..."
With rst
Do Until .EOF
strSQL = Left(BaseSQL, Len(BaseSQL) - 1)
qdf.SQL = strSQL
strEmail = !HWorkEmail
strBodyStart = "" & !FirstName & ", " & vbCrLf & _
vbCrLf & _
"Your current account info is..." & vbCrLf & _
Stuff... vbCrLf
strBody = strBodyStart & strBodyEnd
' Call the Mass Mailing Routine
Call MassMail(strFrom, strBody, strEmail, strSubject)
.MoveNext
Loop
.Close
End With
qdf.SQL = BaseSQL
Set qdf = Nothing
Set rst = Nothing
Set dbs = Nothing
******* End Record Set Code **************************************
******** START OUTLOOK CODE ************************************
Private Sub MassMail(strFrom As Variant, strBody As Variant, strEmail As
Variant, strSubject As Variant)
Dim olApp As Outlook.Application
Dim olMsg As MailItem
Set olApp = CreateObject("Outlook.Application")
Set olMsg = outApp.CreateItem(olMailItem)
With olMsg
.To = strEmail
.SentOnBehalfOfName = strFrom
.Subject = "TEST TEST Please Delete TEST"
.SenderEmailAddress = strFrom
.Body = strBody
.Send
End With
Set olApp = Nothing
Set olMsg = Nothing
End Sub
******** END OUTLOOK CODE ************************************