Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use Outlook 2000 to send new mail to everyone on a distro list

Status
Not open for further replies.

leenabhanot

Programmer
Mar 19, 2001
8
US
Hi I am using Ms Outlook to go through a distro list and send an email to everyone on the list.
For each person, on the distro list, I create a custom report using access and send that as an attachement using a different naming convention for each person.
My problem is that after I have sent the mail to 1 person, I get an error saying that "the object being referenced to has been moved or deleted" I am not really sure how to by pass it.
I am using the following code.
I would appreciate any help. Thanks a lot.

Dim objOL As Object
Dim myItem As Items
Dim a(10) As String
Dim myOLItem As Outlook.MailItem
Dim filename As String
dim fileAttach As Outlook.Attachments

Set objOL = CreateObject("Outlook.Application")
Set myNameSpace = objOL.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myList = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myOLItem = Application.CreateItem(olMailItem)
Set myAttachments = myOLItem.Attachments
Set myDistList = myList.Items.Item("Project Team")

For y = 1 To myDistList.MemberCount
a(y) = myDistList.GetMember(y).Name
myAttachments.Add "C:\" & a(y) & ".xls"
With myOLItem
.To = a(y)
.Subject = "Sample item"
.Body = "This is a sample message."
End With
myOLItem.Send
Next y

Set objOL = Nothing
MsgBox "Done"
 
Hi!

I have exactly the same problem! Therefore I searched the web tonight and found this forum!

I run a query in my Access database and use code to form a mail to send. If I only send one mail everything works perfect, but not with no 2. Then I get "the little red sign" and is thrown out.

A solution of this problem would be very much appreciated.

Rgds
Lisbeth
aka
Lissu

Here is my code:



Dim strMottagare, strÄrende, strMeddelande
Dim dbs As Database, rst As Recordset, rstAnm As Recordset
Dim intDeltNr As Integer, strAnm As String

strÄrende = "Bekräftelse"
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("qryEPostDelt")
Do Until rst.EOF
intDeltNr = rst!deltnr
strMottagare = rst!Epost
strMeddelande = "Hej " & rst!förnamn & "!" & vbNewLine & vbNewLine & _
"Du har anmält dig på följande seminarier:" & vbNewLine & vbNewLine

Set rstAnm = dbs.OpenRecordset("SELECT * FROM qryEpost WHERE DeltNr = " & intDeltNr)

Do Until rstAnm.EOF
strAnm = strAnm & CStr(rstAnm!datum) & " kl " & _
Mid(CStr(rstAnm!kl), 1, 5) & ": " & rstAnm!namn & vbNewLine
rstAnm.MoveNext
Loop
strMeddelande = strMeddelande & strAnm & vbNewLine & vbNewLine & _
"Kontrollera att allt stämmer! " & vbNewLine & vbNewLine & _
"Om inte - hör av dig till Anna Lindén på Office Data, tel 033 - 12 30 50." & vbNewLine & vbNewLine & _
"Många hälsningar" & vbNewLine & _
"Vännerna på Office Data"

If IsNull(strAnm) Then
'MsgBox "tomt"
Else
strÄrende & vbNewLine & strMeddelande

DoCmd.SendObject acSendNoObject, , , strMottagare, , , strÄrende, strMeddelande, False
rst.Edit
rst!mail = False
rst.Update
End If
rst.MoveNext
Loop

Set rst = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top