I have two questions regarding a script I made for sending out email in Access.
(1) I have a working VBA script that opens the Outlook application, if it's not already open, builds the email and then sends it, sort of. When Outlook isn't open the email gets stuck in the outbox until the application is actually running. Then when a send occurs the email is sent. If Outlook is open, then the email gets created and sent all at once.
I've done a search on the web and can't find an answer to whether Outlook needs to be open for the send to occur. Is the script only opening outlook to create the email and set it up to send the next time Outlook opens? Or is there a problem in my script that's causing this to happen.
(2) In my script I have both .Display and .Send. If I comment out, or remove the .Display, my script breaks and fails with an 'Application-defined or object-defined error" message and the .Send is highlighted. Am I missing something in the script that's causing me to need both of these items?
My code is below. Any insight would be appreciated.
Code:
Option Compare Database
Option Explicit
Sub CreateEmail()
'Generate email
Dim OutApp As Object
Dim OutMail As Object
' Opens outlook app and then closes it, if not open
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = "someemail@email.com"
.CC = "moreemail@email.com"
.BCC = ""
'create subject line with file name, user and time submitted.
.Subject = "Feedback on " & Left(CurrentProject.Name, Len(CurrentProject.Name) - 6) & _
" from " & UserFullName & " - " & Date
'.attachments.Add attmt
.Body = "New feedback: " & vbCrLf & Forms!FeedbackF!Commenttxt & vbCrLf & "Left by " & UserFullName & vbCrLf _
& vbCrLf & "This is an automated message, please don't reply directly to the user." & _
vbCrLf & vbCrLf & "Palletizing QSB DBS - " & Now()
'Need both .display and .send to autosend.
.Display
.Send
End With
End Sub
DD