Inspector Wrapper advice for Outlook 2000

  • Thread starter Thread starter Phil Roberts
  • Start date Start date
P

Phil Roberts

Hi everyone,

Could someone please offer some advice on how to proceed with my
Outlook Addin. The goal is to add a combobox, on the standard toolbar,
to mail composition inspectors that adds the selected combobox item to
the mail subject line.

I almost have this going but am having a problem with it working for
multiple inspectors. It works well initally but then the combobox
stops working. My inspector wrapper code is below.

Thanks.

Option Explicit
Private gBaseClass As New OutAddIn
Private WithEvents cbObj As Office.CommandBarComboBox
Private WithEvents m_objInsp As Outlook.Inspector
Private m_nID As Integer

Private Sub Class_Initialize()
Set cbObj = Nothing
Set m_objInsp = Nothing
End Sub

Private Sub Class_Terminate()
Set cbObj = Nothing
Set m_objInsp = Nothing
End Sub

Public Property Let Inspector(objInspl As Outlook.Inspector)
Set m_objInsp = objInspl
End Property

Public Property Get Inspector() As Outlook.Inspector
Set Inspector = m_objInsp
End Property

Public Property Let Key(anID As Integer)
m_nID = anID
End Property

Private Sub m_objInsp_Close()
modOutInsp.KillInsp m_nID, Me
Set m_objInsp = Nothing
If golApp.Explorers.Count <= 1 Then
gBaseClass.UnInitHandler
End If
End Sub

Private Sub m_objInsp_Activate()
Dim cbStandard As CommandBar
Dim cbB As CommandBarButton
Dim cbCB As CommandBarComboBox

Set cbStandard = m_objInsp.CommandBars("Standard")
Set cbCB = cbStandard.FindControl(Tag:="cbObj")

If cbCB Is Nothing Then
Set cbB = cbStandard.FindControl(Id:=2617) 'find the "Send"
item button (ID=2617)

If cbB Is Nothing Then
Exit Sub
End If

Set cbObj = cbStandard.Controls.Add(Type:=msoControlDropdown,
before:=cbB.Index + 1, temporary:=True)

With cbObj 'set combobox properties
.ToolTipText = "Add text to the subject line"
.AddItem "Select...", 1
.AddItem "OPTION 1", 2
.AddItem "OPTION 2", 3
.ListIndex = 1
.DropDownWidth = -1
.Tag = "cbObj"
.Style = msoComboNormal
.Visible = True
.Caption = "Text:"
.OnAction = "!<OptionX.Connect>" 'assign the proc to be
called
.BeginGroup = True
End With
End If
End Sub

Private Sub cbObj_Change(ByVal Ctrl As Office.CommandBarComboBox)
Dim oMail As MailItem

On Error GoTo HelpMe

Set oMail = Application.ActiveInspector.CurrentItem

If Ctrl.Text <> "Select..." Then
oMail.SaveAs "C:\Last.msg", olMSG 'must save to get access to
current subject line
Kill "C:\Last.msg"
oMail.Subject = oMail.Subject & " : " & Ctrl.Text 'add text to
subject
End If

Ctrl.ListIndex = 1

CleanUp:
Set oMail = Nothing 'dispose of object
Exit Sub

HelpMe:
MsgBox "Help Me!", _
vbOKOnly + vbInformation, "Add Text"

GoTo CleanUp
End Sub
 
Ken Slovak - said:
Make sure each instance has a unique tag property.

Thanks Ken. I have done that and moved the combobox onto its own
toolbar. It working well now.

The only remaining issue is that the activate event doesn't seem to
fire consistantly when you click on "Reply" in Outlook 2000 so the
toolbar/combobox aren't always added. Any hints? It's working
perfectly in Outlook 2002. I gather this is a known bug in Outlook
2000.
 
I always handle the Inspector.Activate, .Deactivate and .Close events.
In addition I add WithEvents and event handlers for any item type I
intend to handle in my Inspector event handlers. I use those item
event handlers to take care of Item.Close, .Forward, .Open, .Reply,
..ReplyAll and .Send events. That way I'm not so dependent on the
Outlook version and whether a specific event is handled correctly for
an Inspector.

The are lots of little workarounds needed. For example, if you use the
Next or Previous buttons in an Inspector you may or may not get a
NewInspector event depending on Outlook version. You also will get
different numbers of Inspector.Activate and .Deactivate events
depending on Outlook version, whether Next or Previous was clicked and
whether the item to be opened in the Inspector was opened previously
in that Inspector instance.

Very tricky <g>




Phil Roberts said:
"Ken Slovak - [MVP - Outlook]" <[email protected]> wrote in message
Make sure each instance has a unique tag property.

Thanks Ken. I have done that and moved the combobox onto its own
toolbar. It working well now.

The only remaining issue is that the activate event doesn't seem to
fire consistantly when you click on "Reply" in Outlook 2000 so the
toolbar/combobox aren't always added. Any hints? It's working
perfectly in Outlook 2002. I gather this is a known bug in Outlook
2000.
 
Ken Slovak - said:
I always handle the Inspector.Activate, .Deactivate and .Close events.
In addition I add WithEvents and event handlers for any item type I
intend to handle in my Inspector event handlers. I use those item
event handlers to take care of Item.Close, .Forward, .Open, .Reply,
.ReplyAll and .Send events. That way I'm not so dependent on the
Outlook version and whether a specific event is handled correctly for
an Inspector.

Thanks Ken. By adding mail item event handlers I have managed to get
it adding the toolbar consistantly with Outlook 2000.
The are lots of little workarounds needed. For example, if you use the
Next or Previous buttons in an Inspector you may or may not get a
NewInspector event depending on Outlook version. You also will get
different numbers of Inspector.Activate and .Deactivate events
depending on Outlook version, whether Next or Previous was clicked and
whether the item to be opened in the Inspector was opened previously
in that Inspector instance.

Very tricky <g>

You can say that again! It's been quite a journey getting this to
work. It's a pity Microsoft never got Outlook 2000 quite right.
 
Back
Top