Microsoft example doesn't work 
Author Message
 Microsoft example doesn't work

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



Mon, 01 Sep 2003 07:05:31 GMT  
 Microsoft example doesn't work
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



Quote:
> 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



Mon, 01 Sep 2003 20:35:00 GMT  
 Microsoft example doesn't work
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


Quote:
> 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



> > 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



Tue, 02 Sep 2003 07:05:05 GMT  
 Microsoft example doesn't work
Quote:

> 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]


 Using Virtual Access 4.52 build 277 (32-bit), Windows 2000 build 2195

 Mukilteo, WA  USA



Mon, 01 Sep 2003 16:30:59 GMT  
 Microsoft example doesn't work
Thank you. It's working fine now.

John



Quote:

> > 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]


>  Using Virtual Access 4.52 build 277 (32-bit), Windows 2000 build 2195

>  Mukilteo, WA  USA



Tue, 02 Sep 2003 07:03:33 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Microsoft example doesn't work...

2. Microsoft's KB Q113236 Doesn't work

3. ANOTHER help example doesn't work

4. Process.Start - example doesn't work

5. dotnetfx.exe bootstrapper example setup.exe doesn't work

6. DragIcon Property Problem /VB Example Doesn't work

7. Why doesn't MSDN ListView examples work?

8. Microsoft's tooltip example does not work?

9. Can't get Microsoft DAO example to work, please help

10. Microsoft web control doesn't work

11. fRefreshLinks Doesn't work if path doesn't exist

12. Microsoft VB doesn't know how to talk to Microsoft FoxPro

 

 
Powered by phpBB® Forum Software