R
ryguy7272
I followed the example at this site:
http://support.microsoft.com/kb/318881
It didn't work after I modified the code slightly; trying to use this code:
Sub SendMessages(Optional AttachmentPath)
Dim MyDB As Database
Dim MyRS As Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim TheAddress As String
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("tblMailingList")
MyRS.MoveFirst
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Do Until MyRS.EOF
' Create the e-mail message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
TheAddress = MyRS![EmailAddress]
With objOutlookMsg
' Add the To recipients to the e-mail message.
Set objOutlookRecip = .Recipients.Add(TheAddress)
objOutlookRecip.Type = olTo
' Add the Cc recipients to the e-mail message.
If (IsNull(Forms!frmMail!CCAddress)) Then
Else
Set objOutlookRecip = .Recipients.Add(Forms!frmMail!CCAddress)
objOutlookRecip.Type = olCC
End If
' Set the Subject, the Body, and the Importance of the e-mail message.
.Subject = Forms!frmMail!Subject
.Body = Forms!frmMail!MainText
.Importance = olImportanceHigh 'High importance
'Add the attachment to the e-mail message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve the name of each Recipient.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With
MyRS.MoveNext
Loop
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
Private Sub SendMessg_Click()
Call SendMessages
End Sub
I get this message:
"Run Time Error '13'"
Type Mismatch
Error occurs on this line:
Set MyRS = MyDB.OpenRecordset("tblMailingList")
References are set to
Outlook 10.0 Object Library
Microsoft DAO 3.6 Object Library
I have three text files which I wanted to use as attachments. All are
located in this directory:
C:\Documents and Settings\ThinkPad\Desktop\Text Files
I am just trying to find an easy way to send out a few dozen emails, based
on email addresses saved in a table, which I use for work. One thing that I
am doing different is that I am trying to run the code from a Command Button;
no big deal right. I don’t want to go into the DeBug Window and type any
commands. Should be pretty straightforward; just not seeing the answer
here…. Any help would be greatly appreciated!!
Below, I found a great example of sending multiple emails:
http://www.datastrat.com/DataStrat2.html
‘EmailSenate2K’
This is similar to what I want to do, but it uses a ListBox to display all
(names) recipients of the emails. This is pretty clever; I am just trying to
figure out a way to send multiple emails to people in my office, once per
week, to notify them of updates.
Regards,
Ryan---
http://support.microsoft.com/kb/318881
It didn't work after I modified the code slightly; trying to use this code:
Sub SendMessages(Optional AttachmentPath)
Dim MyDB As Database
Dim MyRS As Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim TheAddress As String
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("tblMailingList")
MyRS.MoveFirst
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Do Until MyRS.EOF
' Create the e-mail message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
TheAddress = MyRS![EmailAddress]
With objOutlookMsg
' Add the To recipients to the e-mail message.
Set objOutlookRecip = .Recipients.Add(TheAddress)
objOutlookRecip.Type = olTo
' Add the Cc recipients to the e-mail message.
If (IsNull(Forms!frmMail!CCAddress)) Then
Else
Set objOutlookRecip = .Recipients.Add(Forms!frmMail!CCAddress)
objOutlookRecip.Type = olCC
End If
' Set the Subject, the Body, and the Importance of the e-mail message.
.Subject = Forms!frmMail!Subject
.Body = Forms!frmMail!MainText
.Importance = olImportanceHigh 'High importance
'Add the attachment to the e-mail message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve the name of each Recipient.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With
MyRS.MoveNext
Loop
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
Private Sub SendMessg_Click()
Call SendMessages
End Sub
I get this message:
"Run Time Error '13'"
Type Mismatch
Error occurs on this line:
Set MyRS = MyDB.OpenRecordset("tblMailingList")
References are set to
Outlook 10.0 Object Library
Microsoft DAO 3.6 Object Library
I have three text files which I wanted to use as attachments. All are
located in this directory:
C:\Documents and Settings\ThinkPad\Desktop\Text Files
I am just trying to find an easy way to send out a few dozen emails, based
on email addresses saved in a table, which I use for work. One thing that I
am doing different is that I am trying to run the code from a Command Button;
no big deal right. I don’t want to go into the DeBug Window and type any
commands. Should be pretty straightforward; just not seeing the answer
here…. Any help would be greatly appreciated!!
Below, I found a great example of sending multiple emails:
http://www.datastrat.com/DataStrat2.html
‘EmailSenate2K’
This is similar to what I want to do, but it uses a ListBox to display all
(names) recipients of the emails. This is pretty clever; I am just trying to
figure out a way to send multiple emails to people in my office, once per
week, to notify them of updates.
Regards,
Ryan---