Email code creates an extra blank email

Big Pat

Registered User.
Local time
Today, 08:19
Joined
Sep 29, 2004
Messages
555
Hi,

I've used other threads here to learn how to create Outlook emails and the following is almost working. The "button" is actually an image (which I forgot to rename!) on the detail section of a continuous view form which displays relevant email addresses against data.

When I click it I get an email with the right address and subject line, exactly as I need it, but I also get another blank email. I can't see anything in my code that could be causing this.



Code:
Private Sub Image29_Click()

'Define variables
Dim strTo As String
Dim strSubject As String
Dim strMessage As String
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem

'Assign values to defined variables
strTo = Me.RDC_Email.Value

strSubject = "Quarterly upload feedback report"

strMessage = vbCrLf & vbCrLf & vbCrLf & "This is the text that will appear" & _
            vbCrLf & "in the body of the email" & vbCrLf & vbCrLf & _
            "For now I have turned this off by commenting out" & vbCrLf & "the relevant line further down."


'Create message
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)


'Display the message
With objOutlookMsg
    objOutlookMsg.To = strToSQL
    objOutlookMsg.Subject = strSubject
'    objOutlookMsg.Body = strMessage
    objOutlookMsg.BodyFormat = olFormatHTML
    objOutlookMsg.Importance = olImportanceNormal
    objOutlookMsg.Display

End With
Set objOutlook = Nothing

End Sub

Any ideas what's causing this? I've closed/reopened Outlook, and compacted and repaired Access db but it's still happening.

Thanks
 
Not sure if it's the cause but why do you use "With objOutlookMsg" and then "objOutlookMsg.To" if ".To" is enough.
 
I'm not sure I understand the question, which is no doubt part of the problem, because I don't fully understand this whole thing, having copied it from another thread and adjusted it as best I can.

I assumed the With / End with means that the statement between them refer to the same thing. And I'm not settinig just the "to" field, but the format, importance, etc.
 
D'oh I see what you mean. I could use

.To
.subject
etc.

I'll try!
 
Tried it. Still the same. At least I've learned a little about coding though :)
 

Users who are viewing this thread

Back
Top Bottom