Mail sits in outbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I know this "subject" has been posted before, but i didn't find this exact
question. I have written some VBA code (in Access 2003) that will open an
outlook application, create an e-mail message, and then send it, but the
message will sit in my outbox until I open outlook again. If outlook is
already visible then the message just goes no problem, but if the last thing
the user does is hit the button that runs my code and then logs off and goes
home for the weekend, then the message doesn't get sent until he logs on on
Monday and opens outlook. I havet ried setting the visible=true property
like you would in Word, but it tells me I can't use that property with
Outlook. Any suggestions?
Our network runs Office 2003 on a Microsoft Exchange Server.

dim OLApp as New Outlook.Application
dim OLMessage as MailItem

set OLMessage = OLApp.CreateItem(olMailItem)
With OLMessage
.To "Address"
.Subject "Subject"
.Body "Body"
.Send
End With
 
You can force a click on "Send/receive all" by code before the
Application terminates:

Dim oCmd as Office.CommandBarButton
Set oCmd=Application.ActiveExplorer.CommandBars.FindControl(,7095)
If not oCmd is nothing then
oCmd.Execute
Endif

(Hope this works in an Exchange environment, too...)
 
Mr. Bauer-

Thanks for the reply. I got at least a few steps closer, but when I run the
code I get a "Method or datamember not found" and it highlights the
..ActiveExplorer in the code you sent. I am assuming I need to add a
reference to a library, but which one? Again, Thanks!

Adam
 
Hi Adam,

you need a ref on Outlook but your code indicates that the ref is there
already.

If your code starts OL then there´s no ActiveExplorer. You need to add
an Explorer instead by Application.Explorers.Add. After your code has
finished close the added Explorer else OL wouldn´t terminate.
 
Well I entered the application.explorers.add line to my code and tried it in
a few different places but now I just get the "method or data member not
found" message on the word "explorers". Perhaps I could tackle this a
different way...As long as outlook is open the message is sent just fine. Is
there a way to just open and show Outlook before the message is sent? I
wouldn't even need to close it again. Like I said before, I tried to use the
visible=true like you do when opening Word or Excel, but for some reason it
wont work on outlook.
 
All-

I just found the solution to my problem in a thread from about a year ago.
For those intereted...

Public Sub EmailTest2()

Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objInbox As Outlook.MAPIFolder
Dim objExplorer As Outlook.Explorer

Set objOL = New Outlook.Application
Set objNS = objOL.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objExplorer = objOL.Explorers.Add(objInbox, olFolderDisplayNormal)
objExplorer.Display

End Sub

This not only creates an outlook application, but shows it as well!
 
You can even save a statement and simply use:

objInbox.Display

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top