Item Remove

The ItemRemove event occurs when an item is removed from a specified Items collection object, either through user action or programmatically. The following example expands on the FolderRemove example described earlier to show how to undelete an item programmatically. This example undeletes a custom form with a message class of IPM.Post.ContactSettings if a user deletes the item from the Settings subfolder of the Inbox.

'Place these declarations in the general section of ThisOutlookSession Public WithEvents colDeletedltems As Outlook.ltems Public WithEvents colSettingsltems As Outlook.ltems Public blnDeleteltem As Boolean

Private Sub Application_Startup() Set objNS = Application.GetNameSpace("MAPI") Set colSettingsltems = _ objNS. GetDefaultFolder(olFolderlnbox).Folders("Settings") Set colDeletedltems = objNS.GetDefaultFolder(olFolderDeletedltems).Items End Sub

Private Sub colSettingsltems_ltemRemove()

blnDeleteltem = True End Sub

Private Sub colDeletedltems_ltemAdd(ByVal Item As Object)

If blnDeleteltem and Item.MessageClass = "IPM.Post.ContactSettings" Then Set objDestFolder = _ objNS.GetDefaultFolder(olFolderlnbox).Folders("Settings")

Item.Move objDestFolder End If blnDeleteltem = False End Sub

Was this article helpful?

0 0

Post a comment