Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.databases.ms-access > #9971
| From | Neil <xxx@gmail.com> |
|---|---|
| Newsgroups | comp.databases.ms-access |
| Subject | Re: Access 2013 and sending an email. |
| Date | 2014-10-03 14:31 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <m0mti2$33c$1@dont-email.me> (permalink) |
| References | <076e8a04-1f71-4d6a-a933-357b195bf2b0@googlegroups.com> <542E3CA2.6040005@gmail.com> <1ffaf00f-b56b-4358-a22b-782fe8821eae@googlegroups.com> |
On 10/3/2014 8:13 AM, Patrick Finucane wrote:
> On Friday, October 3, 2014 2:05:22 AM UTC-4, Neil wrote:
>> On 10/2/2014 12:59 PM, Patrick Finucane wrote:
>>
>>> I'm getting something goofy when I automate an email from Access 2013. Outlook is not open at this point. I press a command button on the form to send an email. The code assigns the email elements (Subject, attachment, To, etc) correctly and displays the email prior to sending. All is good at this point. I then press the SEND buttonin Outlook and the email closes. My code looks like this
>>
>>> If DisplayEmail Then
>>
>>> .Display
>>
>>> Else
>>
>>> .Save
>>
>>> .Send
>>
>>> End If
>>
>>>
>>
>>> After pressing the Send button in Outlook, the Outlook email message is closed. I am sending the message to myself for testing. I will wait forever and no message appears in my inbox. The message will ONLY appear when I open up Outlook. It seems doing so releases the message.
>>
>>>
>>
>>> How can I send an email when Outlook is closed initially? I assume I don't have a property setting set correctly.
>>
>>>
>>
>>
>>
>> Patrick,
>>
>>
>>
>> Where are you looking for the message? If Outlook isn't opened (and only
>>
>> the Outlook Message is displayed), then how would you know whether
>>
>> you've received it or not? Are you using another e-mail reader to look
>>
>> for the message? Looking for it online?
>>
>>
>>
>> Also, when happens if DisplayEmail is False? Does the code send the
>>
>> e-mail OK? Or is it not sent with that option either?
>>
>>
>>
>> For me, whenever I automate Outlook, I create an application object and
>>
>> then the message object, rather than just creating a new message
>>
>> directly. I find that that works better, but YMMV. Also, if the user
>>
>> already has Outlook open, I can just get that instance and use it,
>>
>> instead of opening a new instance.
>>
>>
>>
>> Neil
>
> I set DisplayEmail to False so instead of .Display if did a .Save and .Send and it worked like a champ as expected. If I .Display and press Send, Outlook must be open. It might be because .Display is not Modal and the code following it runs and closes Outlook There is no trapping of errors if I hit cancel instead of send.
>
> Here's my code
> Dim objOutlook As Outlook.Application
> Dim objOutlookMsg As Outlook.MailItem
> Dim objOutlookRecip As Outlook.Recipient
> Dim objOutlookAttach As Outlook.Attachment
> On Error GoTo errorHandler
> ' Create the Outlook session.
> Set objOutlook = CreateObject("Outlook.Application")
> ' Create the message.
> Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
> With objOutlookMsg
> ' Add the To recipient(s) to the message.
> Set objOutlookRecip = .Recipients.Add(varAddress)
> objOutlookRecip.Type = olTo
> .Subject = varSubject
> .body = varBody
>
> ' Add attachments to the message.
> If Not IsMissing(AttachmentPath) And AttachmentPath <> "" Then
> Set objOutlookAttach = .Attachments.Add(AttachmentPath)
> End If
>
> ' Resolve each Recipient's name.
> For Each objOutlookRecip In .Recipients
> objOutlookRecip.Resolve
> Next
> ' Should we display the message before sending?
> If DisplayMsg Then
> .Display 'opens email and continues running. Not modal.
> Else
> .Save
> .Send
> End If
> End With
> Set objOutlook = Nothing
> ExitTheSub:
> Exit Sub
> errorHandler:
> MsgBox "Error occured at Email_Via_Outlook " & Err.NUMBER & ";" & Err.DESCRIPTION
> Resume ExitTheSub
> End Sub
>
Have you tried putting a breakpoint on the set objOutlook = Nothing line
to see what happens?
Back to comp.databases.ms-access | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Access 2013 and sending an email. Patrick Finucane <patrickfinucanetx@gmail.com> - 2014-10-02 10:59 -0700
Re: Access 2013 and sending an email. Norman Peelman <npeelman@cfl.rr.com> - 2014-10-02 19:52 -0400
Re: Access 2013 and sending an email. Patrick Finucane <patrickfinucanetx@gmail.com> - 2014-10-03 06:06 -0700
Re: Access 2013 and sending an email. Norman Peelman <npeelman@cfl.rr.com> - 2014-10-04 08:58 -0400
Re: Access 2013 and sending an email. Patrick Finucane <patrickfinucanetx@gmail.com> - 2014-10-06 06:25 -0700
Re: Access 2013 and sending an email. JB Guernsey <jeff@angelsystems.co.uk> - 2014-10-06 07:58 -0700
Re: Access 2013 and sending an email. Patrick Finucane <patrickfinucanetx@gmail.com> - 2014-10-06 09:27 -0700
Re: Access 2013 and sending an email. JB Guernsey <jeff@angelsystems.co.uk> - 2014-10-06 10:24 -0700
Re: Access 2013 and sending an email. Patrick Finucane <patrickfinucanetx@gmail.com> - 2014-10-06 10:35 -0700
Re: Access 2013 and sending an email. JB Guernsey <jeff@angelsystems.co.uk> - 2014-10-06 13:19 -0700
Re: Access 2013 and sending an email. Neil <xxx@gmail.com> - 2014-10-03 01:05 -0500
Re: Access 2013 and sending an email. Patrick Finucane <patrickfinucanetx@gmail.com> - 2014-10-03 06:13 -0700
Re: Access 2013 and sending an email. Neil <xxx@gmail.com> - 2014-10-03 14:31 -0500
Re: Access 2013 and sending an email. Patrick Finucane <patrickfinucanetx@gmail.com> - 2014-10-06 06:14 -0700
Re: Access 2013 and sending an email. fmsinc <fmsinc@gmail.com> - 2014-10-10 15:44 -0500
csiph-web