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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Automation with Outlook

Status
Not open for further replies.

oaquao

Programmer
May 16, 2001
12
US
I am exporting files to a number of clients, by looping thru
a recordset, I have found that I have to set the object in the loop otherwise it appears that the object is sent and only the first record will be sent. This doesn't seem like the proper way to code this.
Any suggestions on the proper way to code this.
Also does anyone know how to turn off the warning dialog stating that outlook is trying to send a message do you want to allow this, generated when this code is ran.

Any help will be appreciated.
aqua

Public olkApp As Outlook.Application
Public olkNameSpace As Outlook.NameSpace


Public Function email()
Dim rsEmailInfo As New ADODB.Recordset
Dim objMailItem As Outlook.MailItem
Set olkApp = New Outlook.Application
Set olkNameSpace = olkApp.GetNamespace("MAPI")
' Set objMailItem = olkApp.CreateItem(olMailItem)
Set rsEmailInfo = New ADODB.Recordset

rsEmailInfo_Open "Select * from email_Info ", _
CurrentProject.Connection, adOpenForwardOnly

rsEmailInfo.MoveFirst
Do While Not rsEmailInfo.EOF
Set objMailItem = olkApp.CreateItem(olMailItem)

With objMailItem
.To = rsEmailInfo!To
.CC = rsEmailInfo!CC
.Subject = rsEmailInfo!Subject
.Body = rsEmailInfo!Body
.Attachments.Add "C:\Practice.txt"
.Send
End With
rsEmailInfo.MoveNext
Loop

rsEmailInfo.Close
Set objMailItem = Nothing
Set olkNameSpace = Nothing
Set olkApp = Nothing
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top