OL98: Do Not Use "New" Keyword to Declare New Items

ID: Q192861

The information in this article applies to:

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:

   Article-ID: Q180826
   Title     : OL98: Resources for Custom Forms and Programming

   Article-ID: Q182349
   Title     : OL98: Questions About Custom Forms and Outlook Solutions

Additional query words: OutSol OutSol98

Keywords          : kbdta OffVBS
Version           : WINDOWS:
Platform          : WINDOWS
Issue type        : kbinfo

Last Reviewed: November 11, 1998