K
Kristy
Hi
I am creating a Com Add-in for Outlook 2000 and XP. I have used the
ItemsCB example from Microeye as the basis for my project.
I have a query regarding my Inspector wrapper that I am hoping someone
will be able to help me with.
Basically I have 4 class modules ExplOutAddIn.cls, ExplWrap.cls,
InspOutAddIn & InspWrap, and 2 normal modules modOutlInsp and
modOutlExpl that do all the housekeeping for my project.
My issue is that when I send an email m_objInsp_close (the module
responsible for destroying the Inspector object) is not called and
therefore the sent item is not being removed from the Inspector
collection at that time like I'd expect.
Eventually when Outlook is closed m_objExpl_close is called and from
there I call gBaseClassExpl.UnInitHandlerExpl and
gBaseClassInsp.UnInitHandlerInsp to ensure that everything is released
from memory and Outlook closes properly but is this the correct way of
doing it?
I hope that all makes sense... In summary the sent items are
definitely part of the collection when created but they are not
removed from the collection until you exit outlook. I would have
thought that they should be removed on send in the same way that a
closed item is? objMailtItem_close is called but not m_objInsp_close?
Is there a really obvious mistake in my code that I'm missing?
This is basically what happens...
1. Open Outlook, explorer added to collection
Private Sub colExpl_NewExplorer(ByVal Explorer As Outlook.Explorer)
On Error Resume Next
gblnNewExpl = True
AddExpl Explorer
End Sub
2. Open new Mail Item, Inspector added to collection
Private Sub colInsp_NewInspector(ByVal Inspector As Outlook.Inspector)
Dim objItem As Object
Dim strID As String
Set objInsp = Inspector 'declared WithEvents
Set objItem = objInsp.CurrentItem
Select Case objItem.Class
Case olMail
AddInsp Inspector
Set objMailItem = objItem 'declared WithEvents
Case Else
End Select
Set objItem = Nothing
Set objInsp = Nothing
End Sub
3a. Close Item without sending, in this scenario first
objMailitem_close is called then m_objInsp_close is called which
removes the object from the collection
Private Sub objMailItem_Close(Cancel As Boolean)
On Error Resume Next
If objOutlook.Explorers.Count = 0 And objOutlook.Inspectors.Count <=
1 Then
UnInitHandlerInsp
End If
Set objMailItem = Nothing
Set golApp = Nothing
End Sub
Private Sub m_objInsp_Close()
Dim objItem As Object
On Error Resume Next
modOutlInsp.KillInsp m_nID, Me
'MsgBox m_objInsp.Caption & "was just Closed"
Set m_objInsp = Nothing
Set objItem = Nothing
End Sub
Public Sub KillInsp(anID As Integer, objInspWrap As InspWrap)
Dim objInspWrap2 As InspWrap
On Error Resume Next
Set objInspWrap2 = gcolInspWrap.item(CStr(anID))
' ensure removing the correct Inspector from the collection
If Not objInspWrap2 Is objInspWrap Then
Err.Raise 1, Description:="Unexpected Error in KillInsp"
GoTo Cleanup
End If
gcolInspWrap.Remove CStr(anID)
Cleanup:
Set objInspWrap2 = Nothing
End Sub
3b. Open Item is sent, under this scenario objMailItem_Send is
called, then you get a objMailItem_close event and that's it - no
m_objInsp_close.
Private Sub objMailItem_Send(Cancel As Boolean)
'Lots of stuff done here to sent item but it has no effect whether or
not m_objInsp is called so I've left it out.
Finish:
CustomField = ""
Set objItem = Nothing
Set MailItem = Nothing
Set golApp = Nothing
Set strFieldResult = Nothing
End Sub
4. Close Outlook, when you eventually exit outlook m_objExpl is called
and I am currently using this clean up explorer and inspector objects,
it works in that it releases outlook from memory but is it sloppy?
Private Sub m_objExpl_Close()
'On Error Resume Next
modOutlExpl.KillExpl m_nID, Me
Set m_objExpl = Nothing
If Outlook.Application.Explorers.Count <= 1 And
Outlook.Application.Inspectors.Count = 0 Then
gBaseClassInsp.UnInitHandlerInsp
gBaseClassExpl.UnInitHandlerExpl
End If
End Sub
Public Sub KillExpl(anID As Integer, objExplWrap As ExplWrap)
Dim objExplWrap2 As ExplWrap
Set objExplWrap2 = gcolExplWrap.item(CStr(anID))
If Not objExplWrap2 Is objExplWrap Then
Err.Raise 1, Description:="Unexpected Error in KillExpl"
Exit Sub
End If
gcolExplWrap.Remove CStr(anID)
End Sub
I hope that someone understands this and can advise.
Also, as you'll see from the code, I have kept all the Inspector and
Explorer modules completely separate to make it easier for me to
follow as I've worked through everything - should I merge them? Is
this better practice for tidier projects or does it not matter?
Regards
Kristy
I am creating a Com Add-in for Outlook 2000 and XP. I have used the
ItemsCB example from Microeye as the basis for my project.
I have a query regarding my Inspector wrapper that I am hoping someone
will be able to help me with.
Basically I have 4 class modules ExplOutAddIn.cls, ExplWrap.cls,
InspOutAddIn & InspWrap, and 2 normal modules modOutlInsp and
modOutlExpl that do all the housekeeping for my project.
My issue is that when I send an email m_objInsp_close (the module
responsible for destroying the Inspector object) is not called and
therefore the sent item is not being removed from the Inspector
collection at that time like I'd expect.
Eventually when Outlook is closed m_objExpl_close is called and from
there I call gBaseClassExpl.UnInitHandlerExpl and
gBaseClassInsp.UnInitHandlerInsp to ensure that everything is released
from memory and Outlook closes properly but is this the correct way of
doing it?
I hope that all makes sense... In summary the sent items are
definitely part of the collection when created but they are not
removed from the collection until you exit outlook. I would have
thought that they should be removed on send in the same way that a
closed item is? objMailtItem_close is called but not m_objInsp_close?
Is there a really obvious mistake in my code that I'm missing?
This is basically what happens...
1. Open Outlook, explorer added to collection
Private Sub colExpl_NewExplorer(ByVal Explorer As Outlook.Explorer)
On Error Resume Next
gblnNewExpl = True
AddExpl Explorer
End Sub
2. Open new Mail Item, Inspector added to collection
Private Sub colInsp_NewInspector(ByVal Inspector As Outlook.Inspector)
Dim objItem As Object
Dim strID As String
Set objInsp = Inspector 'declared WithEvents
Set objItem = objInsp.CurrentItem
Select Case objItem.Class
Case olMail
AddInsp Inspector
Set objMailItem = objItem 'declared WithEvents
Case Else
End Select
Set objItem = Nothing
Set objInsp = Nothing
End Sub
3a. Close Item without sending, in this scenario first
objMailitem_close is called then m_objInsp_close is called which
removes the object from the collection
Private Sub objMailItem_Close(Cancel As Boolean)
On Error Resume Next
If objOutlook.Explorers.Count = 0 And objOutlook.Inspectors.Count <=
1 Then
UnInitHandlerInsp
End If
Set objMailItem = Nothing
Set golApp = Nothing
End Sub
Private Sub m_objInsp_Close()
Dim objItem As Object
On Error Resume Next
modOutlInsp.KillInsp m_nID, Me
'MsgBox m_objInsp.Caption & "was just Closed"
Set m_objInsp = Nothing
Set objItem = Nothing
End Sub
Public Sub KillInsp(anID As Integer, objInspWrap As InspWrap)
Dim objInspWrap2 As InspWrap
On Error Resume Next
Set objInspWrap2 = gcolInspWrap.item(CStr(anID))
' ensure removing the correct Inspector from the collection
If Not objInspWrap2 Is objInspWrap Then
Err.Raise 1, Description:="Unexpected Error in KillInsp"
GoTo Cleanup
End If
gcolInspWrap.Remove CStr(anID)
Cleanup:
Set objInspWrap2 = Nothing
End Sub
3b. Open Item is sent, under this scenario objMailItem_Send is
called, then you get a objMailItem_close event and that's it - no
m_objInsp_close.
Private Sub objMailItem_Send(Cancel As Boolean)
'Lots of stuff done here to sent item but it has no effect whether or
not m_objInsp is called so I've left it out.
Finish:
CustomField = ""
Set objItem = Nothing
Set MailItem = Nothing
Set golApp = Nothing
Set strFieldResult = Nothing
End Sub
4. Close Outlook, when you eventually exit outlook m_objExpl is called
and I am currently using this clean up explorer and inspector objects,
it works in that it releases outlook from memory but is it sloppy?
Private Sub m_objExpl_Close()
'On Error Resume Next
modOutlExpl.KillExpl m_nID, Me
Set m_objExpl = Nothing
If Outlook.Application.Explorers.Count <= 1 And
Outlook.Application.Inspectors.Count = 0 Then
gBaseClassInsp.UnInitHandlerInsp
gBaseClassExpl.UnInitHandlerExpl
End If
End Sub
Public Sub KillExpl(anID As Integer, objExplWrap As ExplWrap)
Dim objExplWrap2 As ExplWrap
Set objExplWrap2 = gcolExplWrap.item(CStr(anID))
If Not objExplWrap2 Is objExplWrap Then
Err.Raise 1, Description:="Unexpected Error in KillExpl"
Exit Sub
End If
gcolExplWrap.Remove CStr(anID)
End Sub
I hope that someone understands this and can advise.
Also, as you'll see from the code, I have kept all the Inspector and
Explorer modules completely separate to make it easier for me to
follow as I've worked through everything - should I merge them? Is
this better practice for tidier projects or does it not matter?
Regards
Kristy