Microsoft KB Archive/285145

= OL2000: How to Simulate a Form &quot;Create&quot; Event in VBScript =

Article ID: 285145

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Outlook 2000 Standard Edition

-



This article was previously published under Q285145





SUMMARY
Microsoft Outlook does not provide a Microsoft Visual Basic Scripting Edition (VBScript) event that runs only when a new Outlook item is created. This article describes a method you can use to simulate this functionality.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

When a new form is created, Outlook runs an Item_Open event in VBScript. However, after the item is saved in a folder, the Item_Open event also runs when the item is reopened. In addition, Outlook also runs the Item_Read event when an item is opened from a folder.

The following sample VBScript code illustrates how you can place code in the Item_Open event so it will only run when the item is first created. It checks to see if the Created field of the item is populated. If the Created field does not have a date value, the item must be a new item. If the Created field is populated with a date value, the item has already been saved, and is, therefore, being reopened.

Sub Item_Open

MsgBox &quot;This is the Item_Open event.&quot;

' 1/1/4501 represents a Date field with no value. If Item.CreationTime = #1/1/4501# Then MsgBox &quot;Open: Code to run when item created goes here.&quot; Else MsgBox &quot;Open: Code to run when item opened goes here.&quot; End If

End Sub

Sub Item_Read

MsgBox &quot;This is the Item_Read event.&quot;

End Sub

