vlakshmi
Jul 19th, 1999, 12:06 PM
Hi,
I am trying to automate sending emails using Outlook 97. Does it work with Outlook 97 or should I get outlook 98.
The first time I send I can send a mail, but on repeated usage, the outlook is still in the task manager and since it does not exit the program does not work. Is it a problem with my code or using outlook 97.
Please help.
Regards,
lakshmi
Private Sub cmdStartEmail_Click()
Dim Dbs As Database
Dim Rst As Recordset
Dim objOutlook As New Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
' Open Database
Set Dbs = OpenDatabase(App.Path & "\Contacts.mdb")
Set Rst = Dbs.OpenRecordset("Contacts")
Rst.MoveFirst
' Go through each record
Do Until Rst.EOF
'ProgressBar1.Value = Rst.PercentPosition
' Create new message
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
.To = Rst!email
.Subject = "Address Check"
.Body = "Dear " & Rst!Title & " " & Rst!LastName & vbNewLine & vbNewLine
.Body = .Body & "This is an email to confirm your address. "
.Body = .Body & "Please check the address below to make sure "
.Body = .Body & "that it is correct" & vbNewLine & vbNewLine
.Body = .Body & Rst!Address & vbNewLine & Rst!City & vbNewLine
.Body = .Body & Rst!StateOrProvince & vbNewLine & Rst!PostalCode
.Body = .Body & vbNewLine & Rst!Country & vbNewLine & vbNewLine
.Body = .Body & "Tel: " & Rst!PhoneNumber
.Importance = olImportanceHigh
.Send
End With
Set objOutlookMsg = Nothing
Rst.MoveNext
Loop
Rst.Close
' Close Outlook instance: Important!
Set objOutlook = Nothing
' Close database
Dbs.Close
MsgBox "Auto Email Complete", vbInformation
Set Dbs = Nothing
Set Rst = Nothing
End Sub
I am trying to automate sending emails using Outlook 97. Does it work with Outlook 97 or should I get outlook 98.
The first time I send I can send a mail, but on repeated usage, the outlook is still in the task manager and since it does not exit the program does not work. Is it a problem with my code or using outlook 97.
Please help.
Regards,
lakshmi
Private Sub cmdStartEmail_Click()
Dim Dbs As Database
Dim Rst As Recordset
Dim objOutlook As New Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
' Open Database
Set Dbs = OpenDatabase(App.Path & "\Contacts.mdb")
Set Rst = Dbs.OpenRecordset("Contacts")
Rst.MoveFirst
' Go through each record
Do Until Rst.EOF
'ProgressBar1.Value = Rst.PercentPosition
' Create new message
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
.To = Rst!email
.Subject = "Address Check"
.Body = "Dear " & Rst!Title & " " & Rst!LastName & vbNewLine & vbNewLine
.Body = .Body & "This is an email to confirm your address. "
.Body = .Body & "Please check the address below to make sure "
.Body = .Body & "that it is correct" & vbNewLine & vbNewLine
.Body = .Body & Rst!Address & vbNewLine & Rst!City & vbNewLine
.Body = .Body & Rst!StateOrProvince & vbNewLine & Rst!PostalCode
.Body = .Body & vbNewLine & Rst!Country & vbNewLine & vbNewLine
.Body = .Body & "Tel: " & Rst!PhoneNumber
.Importance = olImportanceHigh
.Send
End With
Set objOutlookMsg = Nothing
Rst.MoveNext
Loop
Rst.Close
' Close Outlook instance: Important!
Set objOutlook = Nothing
' Close database
Dbs.Close
MsgBox "Auto Email Complete", vbInformation
Set Dbs = Nothing
Set Rst = Nothing
End Sub