Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Microsoft example doesn't work

0 views
Skip to first unread message

John van Nieuwkerk

unread,
Mar 14, 2001, 6:05:31 PM3/14/01
to
Hi,

I am trying to use code to add an item to a Calendar folder when I close a
Contact item. I found an example which adds a Contact and I thought I would
try that and modify it accordingly. But I get an error running the code in
its original form saying that the object doesn't support this property or
method. The only other difference is that I run this code in an Item_Close()
Function while the example ties it to a Button_Click.

I have highlighted the line where the error occurs.

Dim nmsp 'namespace object
Dim objContactsFolder 'default contacts folder in the logged-on profile
Dim objNewContact 'new contact item object
Dim objUserProperties 'custom fields collection in the current item
Const olFolderContacts = 10 'standard Outlook constant - has to be defined
Set nmsp = Item.Application.GetNameSpace("MAPI")
Set objContactsFolder=nmsp.GetDefaultFolder(olFolderContacts)
Set objNewContact = objContactsFolder.Add ' ERROR OCCURS HERE
Set objUserProperties = Item.UserProperties
objNewContact.Fullname = objUserProperties.Find("txtOrgName").Value
' objNewContact.Email1Address =
objUserProperties.Find("EmailAddress").Value
objNewContact.Save 'release all object variables
Set objNewContact = Nothing
Set objUserProperties = Nothing
Set objContactsFolder = Nothing
Set nmsp = Nothing

Thanks,

John


Sue Mosher

unread,
Mar 15, 2001, 7:35:00 AM3/15/01
to
The line you marked probably fails because you do not have a valid
objContactsFolder object. Why? Because you used olFolderContacts as the
argument for GetDefaultFolder. olFolderContacts is an Outlook constant (=
10), but your code is running in VBScript, which can only use its own
internal VBScript constants. So either declare olFolderContacts as a
constant or use 10 instead.

--

Sue Mosher, Outlook MVP
Author of
Teach Yourself Microsoft Outlook 2000 Programming in 24 Hours
Microsoft Outlook 2000 E-mail and Fax Guide
Outlook and Exchange solutions at http://www.slipstick.com

"John van Nieuwkerk" <joh...@corangamite.vic.gov.au> wrote in message
news:OiITHtNrAHA.2204@tkmsftngp02...

John van Nieuwkerk

unread,
Mar 15, 2001, 6:05:05 PM3/15/01
to
Hello Sue,

I've ordered your Teach ourself book. Hopefully I'll be able to answer a lot
of these questions once I've worked though it.

John

"Sue Mosher" <sue...@slipstick.com> wrote in message
news:OuWOqKVrAHA.1892@tkmsftngp04...

Hollis D. Paul

unread,
Mar 15, 2001, 11:30:59 AM3/15/01
to
In article <OiITHtNrAHA.2204@tkmsftngp02>, John van Nieuwkerk wrote:
> Set objNewContact = objContactsFolder.Add
>
This line is wrong: Set objNewContact = objContactsFolder.Add

Try the following: Set objNewContact = objContactsFolder.Items.Add

Hollis D. Paul [MVP - Outlook]
Hol...@outlookbythesound.com
h...@compuserve.com
Using Virtual Access 4.52 build 277 (32-bit), Windows 2000 build 2195

Mukilteo, WA USA


John van Nieuwkerk

unread,
Mar 15, 2001, 6:03:33 PM3/15/01
to
Thank you. It's working fine now.

John

"Hollis D. Paul" <Hol...@outlookbythesound.com> wrote in message
news:VA.00000a8e.6ba7e73b@obts-outlookdev...

0 new messages