View Single Post
  #1  
Old August 22nd 08, 03:02 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Command Bar Button not working --Inspector Wrapper

Your Activate() handler is calling to createmenu(), not to CreateButton().
It looks to me like at that call the reference to m_obj will be null
(Nothing) since nothing has initialized that object. You also need to set up
a Boolean flag that gets set to True when you have created the UI and check
that flag in Activate() so you don't end up creating new UI each time
Activate() fires. You only want to do that once.

You also should step your code and observe the state of Err and your objects
as you create your UI so you know what's happening.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"amanat via OfficeKB.com" u45636@uwe wrote in message
news:890d7299cd5af@uwe...
Hey Ken ,
Thank you so much for replying to my query.Thanks alot.I have made
changes
in my code according to your suggestions, but Still I am not able to see
command button at all.
Can you please once again check my code .I will be very thankful.


basOutlInsp Code:

Public pinsps_InspWrap As New Collection
Private intID As Integer
Private blnActivate As Boolean

Public Function AddInsp(Inspector As Outlook.Inspector) As String
Dim objInspWrap As New clsinspwrap
Dim objitem As Object
Dim strID As String

On Error Resume Next
'set the Inspector in the class
objInspWrap.Inspector = Inspector

Set objitem = Inspector.CurrentItem
Select Case objitem.Class
Case omail

objInspWrap.Mailitem = objitem

Case Else
End Select
objInspWrap.Key = intID
strID = CStr(intID)
pinsps_InspWrap.Add objInspWrap, strID

objInspWrap.InitButton
AddInsp = strID
intID = intID + 1

Set objInspWrap = Nothing
Set objitem = Nothing
End Function
Public Sub KillInsp(intID As Integer, objInspWrap As clsinspwrap)
Dim objInspWrap2 As clsinspwrap

On Error Resume Next

Set objInspWrap2 = pinsps_InspWrap.Item(CStr(intID))
' check to make sure we're removing the
' correct Inspector from the collection.
If Not objInspWrap2 Is objInspWrap Then
Err.Raise 1, Description:="Unexpected Error in KillInsp"
GoTo ExitSub
End If

pinsps_InspWrap.Remove CStr(intID)

ExitSub:
Set objInspWrap2 = Nothing
End Sub


Private Sub objInsp_Close()
On Error Resume Next

'g_olApp is a global Outlook.Application object that is derived
' from the Application object passed to the COM addin in the
' On_Connection event.
If objoutlook.Explorers.Count = 0 And objoutlook.Inspectors.Count = 1
Then
Set objInsp = Nothing
'call the code to release all Outlook objects
UnInitHandler
End If
End Sub

Public Sub UnInitHandler()
On Error Resume Next
Set objoutlook = Nothing
' Set objitem = Nothing
'Set ctlbtnpriv = Nothing
Set objInsp = Nothing
End Sub


clsinspwrap code:

Option Explicit

Private WithEvents m_objInsp As Outlook.Inspector
Private WithEvents m_objmail As Outlook.Mailitem
Private WithEvents ctlbtnpriv As Office.CommandBarButton
Private m_obj As Object
Private m_intID As Integer
Private mnuTag As String
Private m_blnMailInspector As Boolean
Private m_blnWord As Boolean
Private btnTag As String

Sub ctlBtnPriv_Click(ByVal Ctrl As Office.CommandBarButton, canceldefault
As
Boolean)

Dim strNewToolTip As String
On Error Resume Next

strNewToolTip = "testing123"
Ctrl.ToolTipText = strNewToolTip

End Sub
Private Sub Class_Initialize()
Set m_objInsp = Nothing
Set m_objmail = Nothing
Set ctlbtnpriv = Nothing
m_blnWord = False
Set m_obj = Nothing
End Sub
Private Sub Class_Terminate()
On Error Resume Next
Set m_objInsp = Nothing
Set m_objmail = Nothing
Set ctlbtnpriv = Nothing
Set m_obj = Nothing
End Sub

Public Function InitButton() As Boolean
On Error Resume Next
Call CreateButton(m_objInsp)
End Function

Public Property Let Mailitem(objMail As Outlook.Mailitem)
On Error Resume Next
Set m_objmail = objMail
' m_strmailid = objMail.EntryID
m_blnMailInspector = True
End Property
Public Property Let Inspector(objinspector As Outlook.Inspector)
On Error Resume Next
Set m_objInsp = objinspector
End Property
Public Property Get Inspector() As Outlook.Inspector
On Error Resume Next
Set Inspector = m_objInsp
End Property

Public Property Let Key(lngID As Long)
On Error Resume Next
m_intID = lngID
End Property

Public Property Get Key() As Long
On Error Resume Next
Key = m_intID
End Property
Private Sub m_objMail_Close(Cancel As Boolean)
On Error Resume Next

'can handle various events for the mail item
' in the Inspector like Close and Open.

If Cancel = False Then
Call KillButtons
basoutlinsp.KillInsp m_intID, Me
Set m_objInsp = Nothing
End If

End Sub


Private Sub m_objMail_Open(Cancel As Boolean)
On Error Resume Next

'can handle various events for the mail item
' in the Inspector like Close and Open.
End Sub

Private Sub m_objInsp_Close()
On Error Resume Next

Call KillButtons

basoutlinsp.KillInsp m_intID, Me
Set m_objInsp = Nothing
End Sub

Private Sub KillButtons()
Dim oControl As Office.CommandBarControl

On Error Resume Next

Set oControl = m_obj.CommandBars.FindControl(Tag:=btnTag)
If Not oControl Is Nothing Then
oControl.Delete
End If
Set oControl = Nothing

End Sub
Private Sub CreateButton(objinspector As Outlook.Inspector)
On Error Resume Next
'Adding a new menu item and a button to the main menu for any
Inspector
' must take a different approach if using Word as email editor.
If (objinspector.IsWordMail = True) And _
(objinspector.EditorType = olEditorWord) Then

m_blnWord = True
Set m_obj = Nothing
Else
m_blnWord = False
Set m_obj = objinspector

Call createmenu
End If

Err.Clear

End Sub

Private Sub createmenu()
Dim strToolTip As String
Dim strCaption As String
Dim strKey As String
Dim oCommandBar As Office.CommandBar
Dim oStandardBar As Office.CommandBar
Dim oCBC As Office.CommandBarControl
Dim oControl As Office.CommandBarControl

Set oStandardBar = Nothing

On Error Resume Next

strKey = CStr(m_intID)

'Find Standard Toolbar
For Each oCommandBar In m_obj.CommandBars
If oCommandBar.Name = "Standard" Then
Set oStandardBar = oCommandBar
If oStandardBar Is Nothing Then

Set oStandardBar = m_obj.CommandBars.FindControl(Tag:=btnTag)
End If

Exit For
End If
Next oCommandBar

'Create button
If Not (oStandardBar Is Nothing) Then
oStandardBar.Visible = True

btnTag = "This string is unique to this button" & strKey
strToolTip = "Testing123"
strCaption = "Testing"

Set ctlbtnpriv = oStandardBar.Controls.Add(Type:=msoControlButton,
Temporary:
=True)
With ctlbtnpriv
Caption = strCaption
Tag = btnTag
ToolTipText = strToolTip
Style = msoButtonCaption
Visible = True
End With
End If

Set oControl = Nothing
Set oCommandBar = Nothing
Set oStandardBar = Nothing
'Set oCommandBarButton = Nothing
End Sub

'--------------------------------------------------------------------------
Private Sub m_objInsp_Activate()
On Error Resume Next
'If m_blnButtonsCreated = False Then
'Set m_obj = m_objInsp.WordEditor
Call createmenu
'End If
End Sub

Connect code

Option Explicit

Public WithEvents pinsps As Outlook.Inspectors
Public WithEvents objInsp As Outlook.Inspector
'Public WithEvents ctlbtnpriv As CommandBarButton
Public WithEvents objoutlook As Outlook.Application
'Private WithEvents m_objmail As Outlook.Mailitem
'Private WithEvents colExpl As Outlook.Explorers
'Private WithEvents objmailitem As Mailitem

'************************************************* ********************
'IDTExtensibility2 is the interface that COM Add-Ins must implement.
'The project references the following object libraries:
'Add additional object libraries as required for your COM Add-in.
'References:
'Microsoft Add-In Designer
'Microsoft Outlook 9.0 object library
'Microsoft Office 9.0 object library
'Microsoft Word 9.0 object library
'Microsoft Excel 9.0 object library
'Microsoft PPT 9.0 object library
'Class: Connect
'Purpose: Office 2000 COM Add-in
'Initial Load: Startup
'************************************************* ********************

Implements IDTExtensibility2

Private Sub IDTExtensibility2_OnAddInsupdate(custom() As Variant)

End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
'
End Sub

'************************************************* ********************
'Procedu IDTExtensibility2_OnConnection
'Purpose: Iniitialize gBaseClass and run additional startup code
'************************************************* ********************
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)
'To debug a COM Add-in, uncomment the Stop line below or place
'a breakpoint in the procedure that you want to debug.
'If the COM Add-in is loaded as a compiled dll, you must
'first unload the COM Add-in using the COM Add-Ins dialog box.
'Place the COM Add-in project in Run mode and then
'use the COM Add-Ins dialog box to reload the COM Add-in.
'Stop
'Don't forget to recomment this line when
'you recompile your debugged add-


Set objoutlook = Application
' Set pinsps = Application.Inspectors

End Sub

Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode _
As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
Set objoutlook = Nothing
End Sub

Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)

End Sub

Private Sub pInsps_NewInspector(ByVal Inspector As Inspector)

Dim objitem As Object
Dim strID As String

Set objInsp = Inspector
Set objitem = objInsp.CurrentItem

Select Case objitem.Class

Case olMail
strID = basoutlinsp.AddInsp(Inspector)
Case Else
End Select

Set objitem = Nothing
End Sub




Thank you


Ads