Visio Add-In loses ComboBox WithEvents

T

Trevor Lowing

Problem: I've created an COM Add-In for Visio and one of the features
I've created is a CommandBarDropdown you can use within a Visio document
to navigate to multiple pages. Creating the dropdown went well. So did
populating it with the page names and triggering the page change when
the combo changes. The problem comes when you switch to another Window
or open another document. The first time you switch the combo
repopulates with page names but the combo WithEvents fail. The next
switch and the combo isn't repopulated and the Add-In throws an error i
n the repopulate/refresh function saying "object required".

One thing I'm weary of is ensuring that I've flagged the correct events.
I would assume that the WindowActivated,BeforeWindowClosed,
PageAdded, PageChanged are the correct triggers for clearing or updating
the combo. But somthing is killing the combo WithEvents. Please help.

Here is the relevant code:

Dim WithEvents cboNavigation As Office.CommandBarComboBox
Dim WithEvents m_GlobalApp As Visio.Application

Private Sub cboNavigation_Change(ByVal Ctrl As Office.CommandBarComboBox)
On Error GoTo Err_Init

If Not m_GlobalApp.ActiveDocument Is Nothing Then
m_GlobalApp.ActiveWindow.Page =
m_GlobalApp.ActiveDocument.Pages(cboNavigation.List(cboNavigation.ListIndex))
End If
Exit Sub

Err_Init:
HandleError CurrentModule, "cboNavigation_Change", Err.Number,
Err.Description
'Err.Clear

End Sub

Private Sub m_GlobalApp_WindowActivated(ByVal objWindow As Visio.Window)
'weed out the wrong junk
On Error GoTo Err_Init
Call RefreshNavigation

Exit Sub

Err_Init:
HandleError CurrentModule, "m_GlobalApp_WindowActivated",
Err.Number, Err.Description
'Err.Clear
End Sub

Private Sub m_GlobalApp_BeforeWindowClosed(ByVal objWindow As Visio.Window)
'weed out the wrong junk
On Error GoTo Err_Init
cboNavigation.Clear

Exit Sub

Err_Init:
HandleError CurrentModule, "m_GlobalApp_BeforeWindowClosed",
Err.Number, Err.Description
'Err.Clear
End Sub





Private Sub m_GlobalApp_PageAdded(ByVal objPage As Visio.Page)
'weed out the wrong junk
On Error GoTo Err_Init
Call RefreshNavigation
Exit Sub

Err_Init:
HandleError CurrentModule, "m_GlobalApp_PageAdded", Err.Number,
Err.Description
'Err.Clear
End Sub

Private Sub m_GlobalApp_PageChanged(ByVal objPage As Visio.Page)
'weed out the wrong junk
On Error GoTo Err_Init
Call RefreshNavigation
Exit Sub

Err_Init:
HandleError CurrentModule, "m_GlobalApp_PageChanged", Err.Number,
Err.Description
'Err.Clear
End Sub


Public Function RefreshNavigation()
On Error GoTo Err_Init
'On Error Resume Next

Dim objPage As Visio.Page
Dim intCount, intSelectedIndex As Integer
intCount = 0
If Not m_GlobalApp.ActiveDocument Is Nothing Then
With cboNavigation
.Clear

For Each objPage In m_GlobalApp.ActiveDocument.Pages
intCount = intCount + 1
.AddItem objPage.Name
If objPage.Name = m_GlobalApp.ActivePage.Name Then
intSelectedIndex = intCount
End If

Next
.ListIndex = intSelectedIndex

End With
End If
Set objPage = Nothing
Exit Function

Err_Init:
HandleError CurrentModule, "RefreshNavigation", Err.Number,
Err.Description
'Err.Clear

End Function



---------------------------------
Trevor Lowing
Satellite Beach, Fl

(e-mail address removed)
---------------------------------
Need help with:
Access?
http://www.mvps.org/access/
Outlook?
http://www.slipstick.com/
Visio?
http://www.mvps.org/visio/
HTML/CSS?
http://www.NCDesign.org
Scripting(VBScript/JScript/WSH/XML)?
http://www.DevGuru.com
http://cwashington.netreach.net/
http://developer.irt.org/script/script.htm
---------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top