OL98: Do Not Use "New" Keyword to Declare New Items (192861)



The information in this article applies to:

  • Microsoft Outlook 98

This article was previously published under Q192861

SUMMARY

The Microsoft Outlook 98 object library allows you to initialize a new variable as a particular type of item, such as in the following example:

Dim MyContactItem As New Outlook.ContactItem

However, this syntax should not be supported by the object model and may cause subsequent problems in the code you are creating for a solution.

MORE INFORMATION

All items should be created using the CreateItem or Items.Add methods. The following Visual Basic for Applications example illustrates how to properly early-bind a new object variable and then set it to a new item of a specific type. Be sure to reference the Outlook 98 object library before running this code.
   Sub CreateContact()
      Dim ol As New Outlook.Application
      Dim MyContactItem As Outlook.ContactItem
      Set MyContactItem = ol.CreateItem(olContactItem)
      MyContactItem.Display
   End Sub
				
NOTE: Although the syntax described in the Summary section of this article may work in your solution, future versions of Outlook will not allow this syntax. A compile error will be generated before the code is run.

REFERENCES

For more information about creating solutions with Microsoft Outlook 98, please see the following articles in the Microsoft Knowledge Base:

180826 OL98: Resources for Custom Forms and Programming

182349 OL98: Questions About Custom Forms and Outlook Solutions


Modification Type:MinorLast Reviewed:2/26/2004
Keywords:kbinfo kbprogramming KB192861