I am trying to send an e-mail to all addresses in a query's result. Query is called qryEMailAddresses; the field with address is email.
I have this code associated with a button. Here is the code:
Private Sub cmdSendEmail_Click()
'constants for sending the e-mail
Dim objOutlook As Object
Dim objOutlookMessage As Object
Dim objOutlookRecip As Object
Dim strOutlookAttach As String 'from form entry
Dim strSubject As String
Dim strBody As String
'constants for creating address list
Dim dbs As Database
Dim rst As Recordset
Dim strString As String
Dim strSQL As String 'this will be all names to send to
'create the string for the address
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(qryEMailAddresses)
rst.MoveFirst
Do Until rst.EOF
With rst
strString = strString & " " &
.MoveNext
End With
Loop
' Send the mail
strSubject = txtSubject.Value
strOutlookAttach = txtFileName.Value
strBody = txtBody.Value
Set objOutlook = CreateObject("Outlook.application"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Set objOutlookMessage = objOutlook.createitem(0)
With objOutlookMessage
.bcc = strSQL
.Body = strBody
.subject = strSubject
.attachments.Add strOutlookAttach
.send
End With
Set objOutlookMessage = Nothing
Set objOutlook = Nothing
End Sub
*****************
When I run this, it creates an error at the line "Set rst = dbs.OpenRecordset(qryEMailAddresses)".
Any help would be appreciated.
Dan
I have this code associated with a button. Here is the code:
Private Sub cmdSendEmail_Click()
'constants for sending the e-mail
Dim objOutlook As Object
Dim objOutlookMessage As Object
Dim objOutlookRecip As Object
Dim strOutlookAttach As String 'from form entry
Dim strSubject As String
Dim strBody As String
'constants for creating address list
Dim dbs As Database
Dim rst As Recordset
Dim strString As String
Dim strSQL As String 'this will be all names to send to
'create the string for the address
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(qryEMailAddresses)
rst.MoveFirst
Do Until rst.EOF
With rst
strString = strString & " " &
.MoveNext
End With
Loop
' Send the mail
strSubject = txtSubject.Value
strOutlookAttach = txtFileName.Value
strBody = txtBody.Value
Set objOutlook = CreateObject("Outlook.application"
Set objOutlookMessage = objOutlook.createitem(0)
With objOutlookMessage
.bcc = strSQL
.Body = strBody
.subject = strSubject
.attachments.Add strOutlookAttach
.send
End With
Set objOutlookMessage = Nothing
Set objOutlook = Nothing
End Sub
*****************
When I run this, it creates an error at the line "Set rst = dbs.OpenRecordset(qryEMailAddresses)".
Any help would be appreciated.
Dan