Creating an Outlook Mail message from Access

C

ChrisK

Hi all,

I'm using the following code snippet to create email in Outlook from Access:

Dim appOutlook As Outlook.Application, msg As Outlook.MailItem
On Error GoTo ErrHandler:
Set appOutlook = GetObject(, "Outlook.Application")
Set msg = appOutlook.CreateItem(olMailItem)
With msg
.To = strTo
If strSubject <> "" Then .Subject = strSubject
If strBody <> "" Then .Body = strBody
.Display
End With

Is there a method to bring the Outlook mail item window to the front when
this sub is run? At the moment, when the sub is run, the message is created
but doesn't come to the front

CK
 
D

Dmitry Streblechenko

You can't do that from VBA: if you were using C++ or Delphi, you could query
the Inspector object for the IOleWindow interface, call
IOleWindow::GetWindow, then use the Windows API to bring that window to the
front.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
C

ChrisK

OK, thanks Dmitry...


Dmitry Streblechenko said:
You can't do that from VBA: if you were using C++ or Delphi, you could
query the Inspector object for the IOleWindow interface, call
IOleWindow::GetWindow, then use the Windows API to bring that window to
the front.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
T

Ted

ChrisK:
As an Access developer I have applications that send a lot of emails via
Outlook and I don't worry about seeing them, however if I wanted to see or
edit them, I would put a simple VBA statement in my Access code like this:

DoCmd.SendObject acSendNoObject, , , strTo, , , strSubj, strMsg, True

(The True has it open the email for editing before you send it)

You would still use the If rules to check for your zero length values, but
then use the SendObject instead of the Outlook commands so that you can edit
the email. It should use your default Email program which should be Outlook
if it is installed.

You could use this method at all times unless you wanted to do more such as
add attachments like I do, then you would need to use the Outlook commands.

I hope that help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top