Open MS Outlook from Access

G

Guest

Hello,
I have a button on an Access form that when clicked, I would like the
program to to open MS Outlook to a new message screen so that the user can
type an email. It should check to see if Outlook is already opened. If it
is opened, use that instance and if not, open a new one. I would like
Outlook to become the active window so that the user could do this. In my
reading the forums, I came up with this:

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim MsgText As String
Dim MeetingType As String

'Create the Outlook session
'Set objOutlook = New Outlook.Application
Set objOutlook = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
Set objOutlook = CreateObject("Outlook.Application")
End If

'Create message
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

MeetingType = Forms!MeetingForm!MeetingType

With objOutlookMsg
Select Case MeetingType
Case "IHP"
.Subject = "IHP Meeting Attendees Verified"
Case "IDT"
.Subject = "IDT Meeting Attendees Verified"
End Select

End With

objOutlook.ActiveWindow
'Cleanup
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing

When I run this code, nothing happens. What am I doing wrong? Also, how do
I wait to perform cleanup (set all objects to Nothing), till the user sends
the email? Thanks so much.
Debbie
 
D

David C. Holley

Its not neccessy to DISPLAY the Outlook Application window to create a
new email message (or other Item for that matter).

Set objOutlook = CreateObject("Outlook.Application")
Set newMail = objOutlook.CreateItem(olMailItem)
newMail.display

But if you want the window to show...

Set myNameSpace = objOutlook.GetNameSpace("MAPI")
Set myFolder= myNameSpace.GetDefaultFolder(olFolderInbox)
myFolder.Display

Until you excute the .Display method of the object, the object exists
only in memory. (Like Rose in Titanic - He exists now only in my memory.)

David H
 
D

David C. Holley

Not that I have any experience with getting Access to control Outlook or
anything....(have been do so for what seems an eternity)
 

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