PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook VBA Programming Using VBA for Outlook and VBA for Access within Access

Reply

Using VBA for Outlook and VBA for Access within Access

 
Thread Tools Rate Thread
Old 17-03-2006, 11:27 AM   #1
=?Utf-8?B?U2FyZG9uaWM=?=
Guest
 
Posts: n/a
Default Using VBA for Outlook and VBA for Access within Access


I have an access application which is successfully calling the following VBA
procedures:

1) ns.Logon
2) stDocName = "Client Activity"
DoCmd.OpenForm stDocName, , , stLinkCriteria

However, the following procedure throws a compile error, "Method or Data
Member not found" - and highlights the .CreateItem method. What shall I do
to make this code work - I've adapted from VBA for Absolute beginners.
(p230-235) I have added the Outlook 11.0 library as a referece to my copy of
access.


Dim ol As Outlook.Application
Dim ns As NameSpace
Dim msg As MailItem

Set ol = CreateObject("Outlook.Application")
Set ns = ol.GetNamespace("MAPI")

ns.Logon

Set msg = Application.CreateItem(olMailItem)

With msg
.Receipents.Add "email 1"
.Recipients.Add "email 2"
.Subject = "test1"
.Body = "This is a test"
End With

ns.Logoff



  Reply With Quote
Old 17-03-2006, 12:34 PM   #2
Sue Mosher [MVP-Outlook]
Guest
 
Posts: n/a
Default Re: Using VBA for Outlook and VBA for Access within Access

You need to use the Outlook.Application object you created, not the Access Application object:

Set msg = ol.CreateItem(olMailItem)

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Sardonic" <Sardonic@discussions.microsoft.com> wrote in message news:42FBFD14-BE7B-4013-AFAB-61C5DEA5A53A@microsoft.com...
>I have an access application which is successfully calling the following VBA
> procedures:
>
> 1) ns.Logon
> 2) stDocName = "Client Activity"
> DoCmd.OpenForm stDocName, , , stLinkCriteria
>
> However, the following procedure throws a compile error, "Method or Data
> Member not found" - and highlights the .CreateItem method. What shall I do
> to make this code work - I've adapted from VBA for Absolute beginners.
> (p230-235) I have added the Outlook 11.0 library as a referece to my copy of
> access.
>
>
> Dim ol As Outlook.Application
> Dim ns As NameSpace
> Dim msg As MailItem
>
> Set ol = CreateObject("Outlook.Application")
> Set ns = ol.GetNamespace("MAPI")
>
> ns.Logon
>
> Set msg = Application.CreateItem(olMailItem)
>
> With msg
> .Receipents.Add "email 1"
> .Recipients.Add "email 2"
> .Subject = "test1"
> .Body = "This is a test"
> End With
>
> ns.Logoff
>
>
>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off