Results 1 to 4 of 4
  1. #1
    chris.williams is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    94

    Object Variable Not Set when Outlook is running

    Hi all - I have a function that creates an Outlook object and sends an email.



    The routine works great when Outlook is not running. The problem is that no email is sent without opening outlook. All the messages are stuck in the outbox queue.

    As a work around, I thought about running Outlook in the back ground, but when Outlook is running, I get a runtime error 91 - Object Variable not set.

    Here's my code to reference - any ideas are appreciated.

    Code:
    Set objOutlook = CreateObject("Outlook.application")
    
    Set objEmail = objOutlook.CreateItemFromTemplate(varEmailTemplate)
    With objEmail
    .To = varSendTo
    .cc = varSendCC
    .Subject = varSubject
    .Body = varBody
    '.HTMLBody = varHTMLBody
    .Attachments.Add varAttachment
    .Display
    .SentOnBehalfOfName = varSendFrom
    '.Send
    '.ReadReceiptRequested
    End With
    Ideally, I would like the messages to be sent automatically without opening Outlook, but I believe that is how Outlook functions. The next best method would be to have Outlook running in the background.

    Thanks...

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Code:
    semailto = "test@testing"
    sbody = "test email body"
    DoCmd.SendObject acSendNoObject, , , semailto, , , sbody, , False
    I sent this email without opening outlook

    EDIT: just noticed it in my outbox when I opened after a second test, must have been too quick the first time to catch.

    There are tons of solutions out there but they all involve installing dll's to help with the process, how much latitude do you have in installing additional software to handle emailing without using outlook?

    Here's a link to one that doesn't seem to require a dll though:

    http://www.dbforums.com/microsoft-ac...t-outlook.html

  3. #3
    chris.williams is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    94
    We are a large company with desktops locked down. We cannot install any other components - unfortunately. I am also bound to using the method I have outlined above as I need the body of the email to be HTML and to have multiple attachments. DoCmd.SendObject does not support those requirements.

    Thanks for the input.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Did you look at the second method in the link, I didn't test it but the article said nothing about installing any outside drivers.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 05-20-2014, 11:32 AM
  2. Replies: 0
    Last Post: 08-10-2011, 11:59 AM
  3. Object variable or With block variable not set
    By walter189 in forum Programming
    Replies: 1
    Last Post: 07-28-2011, 08:51 AM
  4. Outlook Object Model question - automation
    By yeah in forum Programming
    Replies: 1
    Last Post: 11-23-2010, 02:05 PM
  5. Replies: 4
    Last Post: 08-05-2010, 01:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums