Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd.SendObject Stores Emails in Outlook Outbox But No Send

Status
Not open for further replies.

grgimpy

Programmer
Nov 1, 2006
124
0
0
US
I have a weird problem with sending e-mails in Access using VBA which differs from computer to computer. On the user's computer, Microsoft Outlook is not open. When entering data into the Access Forms, sometimes an event is triggered which sends out an E-mail.

On some of the computers, this e-mail will still be sent out even though Outlook is not visibly open. On the other computers, the e-mail will be stored in the Outbox of Outlook, and will not be sent until the Outlook program is opened manually by the user.

I looked around at the settings in Outlook and could not figure out what was different in the Outlook settings that allowed some computers to send e-mails when Outlook was not open, while the others cannot.

Has anyone ever run into this problem? I can't have Outlook open at all times b/c I can't make sure that the users will keep it open. I know its possible to send e-mails using the DoCmd.SendObject coding with Outlook closed, but just can't figure out the Outlook settings that would allow me to do this.

Thanks for any help if you've run into this problem before.
 
First let me say that if Outlook is the default mail program and you do a docmd.sendobject then Outlook will open, not visible, the message will be sent and Outlook will be closed. Outlook is a resource dog (probably why users don't keep it running) so if you are sending more than the occasional e-mail, it is best they keep it open.

I can't believe your users put up with the prompting to use Outlook (assuming patched Outlook 2000 or later).

That aside, sometimes Outlook is just flaky about sending messages. It either it can't connect or is just playing dumb. I don't remember ever having this problem in Outlook 2003. It was somewhat rare in 2000. Occassionally it happened in Outlook 98. Outlook 97 is so horrid with bugs that you should do whatever it takes to upgrade.

All that said, I would look into the network connectivity first. Upgrade to at least Outlook 2000 sp1 with no patches(last version that doesn't harrass when someone trys to send an e-mail). Then I guess it is the reliablity of the systems or smtp server if you are not using Exchange server.

Another thought... Maybe Oulook is trying close while the message is queue'd (outbox) before it can be sent. Seems odd but you may have some luck going someing like...

Code:
Dim OutApp as Obj

set OutApp = Createobject("Outlook.application")

docmd.sendobject ...

Sleep 2000 'or some other code to pause depending of Acces version you are using

set outapp = Nothing

The problem with the above it is sloppy... It will open and not close outlook everytime you want to send a message.
 
Thanks for the input. E-mails are only sent occasionally, so it's not a big problem that Outlook is closed most of the time. Also, I have a program that instantly clicks "yes" to send the e-mail, so the users never really know that prompt is coming up.

This is just a tricky situation. The users are not great at using computers, and they really don't want to learn much either besides how to add these records because we make them. They couldn't care less about sending these e-mails out. But anyways, I'll give your suggestion a try. I appreciate it.
 
I think you will have problems using my idea if the users are really that unsavy.

I would try researching the e-mail problem. I am sure you will need to know the connection type (i.e. SMTP / Exchange) for Outlook.

Are you sending a large attachment?
I am just thinking that Access must be instantiating Outlook and running the send asynchronously so it ends up closing before the send is complete...

Maybe you should try automating Outlook...
I don't have an example handy but I bet you could find one by doing a search.

 
i think you should try to make outlook open by it self before sending the mail and close it after he sended the email
 
I had this same problem. I would have over 200 emails just sitting in the outbox, sometimes the emails weren't even genereated, access just simply crashed and nothing happened. I'd have to send it all manually when it actually did work.

So - I wiped the hard drive clean, reinstalled XP and only the office suite,re-ran the app - never had the problem ever again. Code worked perfectly without any changes. Put all the code behind an invisible form_open command and scheduled it to run via "Scheduled Task" in XP at 5AM and it has worked perfectly ever since.

 
What I ended up doing was making sure that Outlook was always open when the users were using the forms. I used the following code, and set up Outlook to be hidden when minimized (right click on the Outlook icon in the system tray and you'll see the option.

This was as weird glitch in that it worked on half the computers and not on the others. This fix works well though, so I'm happy.


Code:
Private Sub Form_Load()
On Error Resume Next

    DoCmd.Maximize

'Open Outlook and minimize it in system tray
'In order to have Outlook minimize in system tray
'must right click on system tray icon and select
'"Hide When Minimized"
'Note: Must go to Tools-References and select
'Microsoft Outlook 11.0 Object Library for this code to
'work properly

Dim Olook As Outlook.Application

'Determine if Outlook is already open so
'that multiple Outlook windows are not opened
'If Outlook is not open an error will occur
'but the code will move forward because of
'the above code "On Error Resume Next"
    Set Olook = GetObject(, "Outlook.Application")

'Now any Errors will be handled differently
On Error GoTo Err_Handler

'If Outlook is not open then it will be opened
'by the following code.
    If Olook Is Nothing Then

        Set Olook = CreateObject("Outlook.Application")

Dim ns As Outlook.NameSpace
Dim Folder As Outlook.MAPIFolder

        Set ns = Olook.GetNamespace("MAPI")
        Set Folder = ns.GetDefaultFolder(olFolderOutbox)

'Display Outlook
        Folder.Display

'Minimize Outlook
        Olook.ActiveExplorer.WindowState = 1

    End If

Exit_Handler:
    Exit Sub
Err_Handler:
    MsgBox Err.Description
    Resume Exit_Handler
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top