L
L Walsh via AccessMonster.com
I have created an Access function to create Outlook emails to email addresses
stored in an Access table. I want the emails to be saved in the Drafts folder
so that can be reviewed before sending. I've got a command button on a form
whose data source is a query for all the records to receive an email. It's
working fine, except sometimes the first email is created in the Inbox, and
all the rest go into the Drafts. Why am I sometimes getting one in the Inbox?
Any advice greatly appreciated.
Here is my code:
Private Sub Create_Emails_Click()
On Error GoTo Err_Create_Emails_Click
Dim oApp As Outlook.Application
Dim objNewMail As Outlook.MailItem
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim rcdMemotext As DAO.Recordset
Set db = CurrentDb
Set rs = Me.RecordsetClone
Set oApp = New Outlook.Application
Set rcdMemotext = db.OpenRecordset("Memotext", dbOpenSnapshot)
rcdMemotext.FindFirst "ID = 'Email text'"
rs.MoveFirst
Do While Not rs.EOF
Set objNewMail = oApp.CreateItem(olMailItem)
With objNewMail
.To = rs![E-mail Address]
.Subject = "Test email"
.Body = rcdMemotext![Memo1] & rs![First Name] & "," & vbCrLf & vbCrLf
.Body = .Body & rcdMemotext![Memo2] & vbCrLf & vbCrLf
.Body = .Body & rcdMemotext![Memo3] & vbCrLf & vbCrLf
.Save
End With
rs.MoveNext
Loop
Exit_Create_Emails_Click:
Exit Sub
Err_Create_Emails_Click:
MsgBox Err.Description
Resume Exit_Create_Emails_Click
End Sub
stored in an Access table. I want the emails to be saved in the Drafts folder
so that can be reviewed before sending. I've got a command button on a form
whose data source is a query for all the records to receive an email. It's
working fine, except sometimes the first email is created in the Inbox, and
all the rest go into the Drafts. Why am I sometimes getting one in the Inbox?
Any advice greatly appreciated.
Here is my code:
Private Sub Create_Emails_Click()
On Error GoTo Err_Create_Emails_Click
Dim oApp As Outlook.Application
Dim objNewMail As Outlook.MailItem
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim rcdMemotext As DAO.Recordset
Set db = CurrentDb
Set rs = Me.RecordsetClone
Set oApp = New Outlook.Application
Set rcdMemotext = db.OpenRecordset("Memotext", dbOpenSnapshot)
rcdMemotext.FindFirst "ID = 'Email text'"
rs.MoveFirst
Do While Not rs.EOF
Set objNewMail = oApp.CreateItem(olMailItem)
With objNewMail
.To = rs![E-mail Address]
.Subject = "Test email"
.Body = rcdMemotext![Memo1] & rs![First Name] & "," & vbCrLf & vbCrLf
.Body = .Body & rcdMemotext![Memo2] & vbCrLf & vbCrLf
.Body = .Body & rcdMemotext![Memo3] & vbCrLf & vbCrLf
.Save
End With
rs.MoveNext
Loop
Exit_Create_Emails_Click:
Exit Sub
Err_Create_Emails_Click:
MsgBox Err.Description
Resume Exit_Create_Emails_Click
End Sub