Yes, you can place the code in any Event Procedure, Function, Sub-Routine, etc.
Ok so say I had a query of a table that gave me a subset of data called query1 for simplicity sake. I am trying to setup an automatic email follow up to these inquiries. I have email code that works but It only sends that one record. the code i have is below: I am sorry to be a pain but it would be so much easier to get this to work through a group of emails rather than use mail merge, just an extra step for people that I am trying to eliminate. If I wrap your code around this will it send the email out to that query set?
Private Sub Command20_Click()
Dim mess_body As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.BodyFormat = olFormatRichText
.To = Me.Email_Address
.Subject = Me.Mess_Subject
.HTMLBody = Me.Mess_Text
If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
.Attachments.Add (Me.Mail_Attachment_Path)
End If
'.DeleteAfterSubmit = True 'This would let Outlook send th note without storing it in your sent bin
.Send
End With
'MsgBox MailOutLook.Body
Exit Sub
email_error:
MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
Resume Error_out
Error_out:
End Sub