SendObject Stuck in Outbox

BrianB75

Registered User.
Local time
Today, 14:32
Joined
Aug 27, 2004
Messages
43
Here is an odd one. I have quite a few reports that have been running fine for years on an older WinXP PC (Office 2002). Since switching to a Win7 PC, all of the reports that are sent via SendObject (either in a macro or in a module) are being created correctly but get stuck in Outlook's outbox. I have to open Outlook (never needed to remain open on the XP PC) and manually click Send/Receive. This causes issues as most of the reports are scheduled to run before anyone is in the office. The odd part is this, when I use code to create the e-mail (not the docmd) it not only fires off the e-mail correctly but also sends all the items sitting in the outbox at that time. Here is the sample code:

Code:
Public Function test_module_send()

Dim dbs As Database, obEmail As Object, obMsg As Object, mynamespace As Outlook.NameSpace

Set dbs = CurrentDb
Set obEmail = CreateObject("Outlook.Application")
Set obMsg = obEmail.CreateItem(olMailItem)

DoCmd.SendObject acSendNoObject, , , "Email Address", , , "Testing SendObject", , no

With obMsg
    .subject = "Test Module Send"
    .To = "email address"
    .Body = "Testing"
    .Send
        
End With

Set obEmail = Nothing
Set obMsg = Nothing
Set obAttachment = Nothing


End Function

If I run it as-is it works fine but as soon as I comment out everything in between the With and End With the e-mails get stuck.

I have checked through all of the settings in Outlook (2007) and even compared the settings to what is available in the old version of Outlook (2002) and cannot track down the issue.
 
The Set obmsg might create a 'draft'

I would use this and not the docmd statement, ie keep the with statement and comment out the docmd bit

Steve
 
That is what I am afraid of...;)

I am just confused on what changed in either Access 07 or Outlook 07 compared to Office 2002 that caused this to stop working correctly.
 
Your code is a bit weird mix af early and late binding. Since you on one hand declare the objects as for late binding, but also mynamespace as Outlook.NameSpace, implying that you have set up references to outlook. Because with late binding constants like olMailItem are not defined, but since the compiler seemingly doesn't squeal ...so perhaps that is not the cause of your problem.

AFAIK Outlook2007 has a different security model from 2003, and the thing, per definition, objects to anything you may want to do programmaticaly - without user interaction - from the outside. Does it not yell at all when SendObject is used? No messages in outlook or access?
 
Last edited:
That mess of code was just a sample I was using to test out the new PC. Almost all of my older code uses only the docmd, and then typically directly in a macro and not in code.

Oddly, I get no messages from either Access or Outlook but then I do have the Trust Center setup so that the database locations are trusted.

Our temp solution here has been to set up a VM with WinXP/OfficeXP to run the older code while I go about updating it for Office2007. Sadly, we could not track down a workaround to the 07 security.
 
One can spend a lot of effort on searching for explanations. Alternatively make it work.

Since your direct calling of Outlook stuff apparently does what you want, I would make a subroutine that has the same list of optional arguments as DoCmd.SendObject and do a global replace on DoCmd.SendObject with your sub - in code and in macros.
 
Thanks again. I was trying to avoid that but it is better code to use so I'm just going to bite the bullit and update my code. On the plus side, it will give me the oppertunity to clean up my old marcos/code a bit. :)
 
I would urge you to sit tight on any code-cleaning desires until they fade away. Code that works, however inelegant it may be, still works. After your "cleaning" - you still have the code that works, and nothing new. So what is the point? And "cleaning" is like a Pandora's box - all kinds of stuff creep out from under the carpe, and you can spend ages on beautification. :D
 

Users who are viewing this thread

Back
Top Bottom