J
John Ford
I have a form with some scripting for the Item_Open event. When the
work is done, I want to "not open" the item, so I have Item_Open =
False just before the End Function for Item_Open.
This causes Outlook to abort, the kind that offers to send an error
report to MicroSoft.
Why/When can't I "not open" an item?
The "work" my Item_Open function does is to publish another form
(comes attached to the problematic form). Here's the code...
Function Item_Open()
If Item.Attachments.Count = 1 Then
Dim oFS 'As Scripting.FileSystemObject
Dim oForm 'As Outlook.MailItem
Dim oAtt ' As Outlook.Attachment
Dim sPath 'As String
Dim oFD 'As Outlook.FormDescription
Const olPersonalRegistry = 2
Const TemporaryFolder = 2
set oAtt = attachments(1)
Set oFS = CreateObject("Scripting.FileSystemObject")
sPath = oFS.GetSpecialFolder(TemporaryFolder).Path _
& "\" & oAtt.FileName
oAtt.SaveAsFile sPath
Set oForm = Application.CreateItemFromTemplate(sPath)
oFS.DeleteFile sPath
Set oFD = oForm.FormDescription
oFD.DisplayName = oAtt.DisplayName
oFD.PublishForm olPersonalRegistry
MsgBox oFD.DisplayName _
& " published to your Personal Forms Library"
Set oForm = Nothing
Set oFD = Nothing
Set oFS = Nothing
Item_Open = False End If
End Function ' <<<<< error happens after function end
work is done, I want to "not open" the item, so I have Item_Open =
False just before the End Function for Item_Open.
This causes Outlook to abort, the kind that offers to send an error
report to MicroSoft.
Why/When can't I "not open" an item?
The "work" my Item_Open function does is to publish another form
(comes attached to the problematic form). Here's the code...
Function Item_Open()
If Item.Attachments.Count = 1 Then
Dim oFS 'As Scripting.FileSystemObject
Dim oForm 'As Outlook.MailItem
Dim oAtt ' As Outlook.Attachment
Dim sPath 'As String
Dim oFD 'As Outlook.FormDescription
Const olPersonalRegistry = 2
Const TemporaryFolder = 2
set oAtt = attachments(1)
Set oFS = CreateObject("Scripting.FileSystemObject")
sPath = oFS.GetSpecialFolder(TemporaryFolder).Path _
& "\" & oAtt.FileName
oAtt.SaveAsFile sPath
Set oForm = Application.CreateItemFromTemplate(sPath)
oFS.DeleteFile sPath
Set oFD = oForm.FormDescription
oFD.DisplayName = oAtt.DisplayName
oFD.PublishForm olPersonalRegistry
MsgBox oFD.DisplayName _
& " published to your Personal Forms Library"
Set oForm = Nothing
Set oFD = Nothing
Set oFS = Nothing
Item_Open = False End If
End Function ' <<<<< error happens after function end