ribbon dropDowns from SQL using Word 2007, VSTO2005 SE and .net Sh

S

slaprade

I am using Word 2007, VSTO2005SE and Visual Studio VB to create a shared
addin automation app.

I have an "other" app that launches Word calling a particular Sub in my dotm
file

The dotm declares the addin like this "Public MCTai As New MCTClass07.Class07"

The dotm calls Class07 routines that load Class07 tables from SQL. This call
resides in the routine called by the "other" app

Subs executed from the dotm that display table.row.count show that these
tables have data

I have created Tabs in the Ribbon with some success using callbacks for
buttons to the .net code

The problem starts when I try to populate a dropDown with data from these
local tables

I can populate the dropDown with static data in the GetItemCount,
GetItemLabel and GetItemID functions

When I replace the static data with table information like GetItemLabel =
DV_APC.Item(X).Item(1).ToString, I get error messages NOT when Word starts
but when I try to select the dropDown. The error messages indicate there is
no data in DV_APC

When I put a MSGBOX for the table.row.count of a table in the GetItemLable
function, it displays 0 rows

The core of the dotm looks like this

Public WithEvents appWord As Word.Application
Public MCTai As New MCTClass07.Class07

Public Function MSGatewayInitialize(OdbcStr As String, LibName As String,
recordID As Long, docName As String, ByRef rcMsg As String) As Long
Dim returnCode As Long

returnCode = 0
Call Register_Event_Handler(OdbcStr) 'add event handler

On Error GoTo init_error

Call MCTai.InitDocument(ActiveDocument, OdbcStr, LibName, recordID)
Call Module1.KeepData(OdbcStr, LibName) 'this call will save data to
MCTai and load tables from SQL

On Error GoTo 0
MSGatewayInitialize = returnCode
Exit Function

init_error:
MsgBox (Err.Description) + vbCrLf + "Initialization error"
Err.Clear
returnCode = -1

End Function

So my question may be "What is the order of these parts loading"?

Or my question may be "how do I read SQL tables into the dropDowns of the
ribbon since I have to make the queries to SQL from my code"?
 
S

slaprade

sure - here is the ribbon XML

<group id="MCTCat" label="Categories" >
<dropDown id="APCat"
getItemCount="GetItemCount"
getItemID="GetItemID"
getItemLabel="GetItemLabel"/>
<dropDown id="ChooseDepartment" label="AP Cat">
<item id="Dept1" label="Shipping" />
<item id="Dept2" label="Accounting"/>
<item id="Dept3" label="Engineering" />
</dropDown>
</group>

and the .net code

Public Function GetItemCount(ByVal control As IRibbonControl) As Integer
Select Case LCase(control.Id)
Case Is = "apcat"
GetItemCount = 4
End Select
End Function

Public Function GetItemLabel(ByVal control As IRibbonControl, ByVal
index As Integer) As String
Dim zz(6) As String
'Dim X As Integer
'For X = 0 To UBound(zz)
' zz(X) = DV_APC.Item(X).Item(1).ToString
'Next

'Select Case LCase(control.Id)
' Case Is = "apcat"
' GetItemLabel = zz(index)
'End Select
''Dim zz(6) As String
zz(0) = "0"
zz(1) = "1"
zz(2) = "2"
zz(3) = "3"
zz(4) = "4"
zz(5) = "5"

GetItemLabel = index.ToString
MsgBox(DV_APC.Count)
End Function

Public Function GetItemID(ByVal control As IRibbonControl, ByVal index
As Integer) As String
GetItemID = control.Id.ToString + index.ToString
End Function


I tried various ways to get the DV_APC (dataview of a table) data into the
ribbon
one that has been delete is in GetItemLabel
GetItemLabel = DV_APC.item(index).item(1).tostring

When that didn't work I though maybe the data had to be in an array which is
what you see above

the MSGBOX in GetItemsLabel shows a 0 for each request (number of which is
determined by GetItemCount) when I attempt to access the dropDown and only
when I attempt to access the dropDown (not at word startup)


Patrick Schmid said:
Can you show your RibbonX code?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

I am using Word 2007, VSTO2005SE and Visual Studio VB to create a shared
addin automation app.

I have an "other" app that launches Word calling a particular Sub in my dotm
file

The dotm declares the addin like this "Public MCTai As New MCTClass07.Class07"

The dotm calls Class07 routines that load Class07 tables from SQL. This call
resides in the routine called by the "other" app

Subs executed from the dotm that display table.row.count show that these
tables have data

I have created Tabs in the Ribbon with some success using callbacks for
buttons to the .net code

The problem starts when I try to populate a dropDown with data from these
local tables

I can populate the dropDown with static data in the GetItemCount,
GetItemLabel and GetItemID functions

When I replace the static data with table information like GetItemLabel =
DV_APC.Item(X).Item(1).ToString, I get error messages NOT when Word starts
but when I try to select the dropDown. The error messages indicate there is
no data in DV_APC

When I put a MSGBOX for the table.row.count of a table in the GetItemLable
function, it displays 0 rows

The core of the dotm looks like this

Public WithEvents appWord As Word.Application
Public MCTai As New MCTClass07.Class07

Public Function MSGatewayInitialize(OdbcStr As String, LibName As String,
recordID As Long, docName As String, ByRef rcMsg As String) As Long
Dim returnCode As Long

returnCode = 0
Call Register_Event_Handler(OdbcStr) 'add event handler

On Error GoTo init_error

Call MCTai.InitDocument(ActiveDocument, OdbcStr, LibName, recordID)
Call Module1.KeepData(OdbcStr, LibName) 'this call will save data to
MCTai and load tables from SQL

On Error GoTo 0
MSGatewayInitialize = returnCode
Exit Function

init_error:
MsgBox (Err.Description) + vbCrLf + "Initialization error"
Err.Clear
returnCode = -1

End Function

So my question may be "What is the order of these parts loading"?

Or my question may be "how do I read SQL tables into the dropDowns of the
ribbon since I have to make the queries to SQL from my code"?
 
P

Patrick Schmid [MVP]

I think there might be some misunderstanding as to how this works.
Office first calls GetItemCount to determine how many items there are in
the dropdown. Then it will call GetItemLabel for every single one of
those items. So if you give it a count of 4, GetItemLabel will be called
four times. The index that is passed into the method is a simple
zero-based index. So the first one is 0, second 1, etc.
The other thing you should check is whether the dataview is even defined
at this point in time.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

sure - here is the ribbon XML

<group id="MCTCat" label="Categories" >
<dropDown id="APCat"
getItemCount="GetItemCount"
getItemID="GetItemID"
getItemLabel="GetItemLabel"/>
<dropDown id="ChooseDepartment" label="AP Cat">
<item id="Dept1" label="Shipping" />
<item id="Dept2" label="Accounting"/>
<item id="Dept3" label="Engineering" />
</dropDown>
</group>

and the .net code

Public Function GetItemCount(ByVal control As IRibbonControl) As Integer
Select Case LCase(control.Id)
Case Is = "apcat"
GetItemCount = 4
End Select
End Function

Public Function GetItemLabel(ByVal control As IRibbonControl, ByVal
index As Integer) As String
Dim zz(6) As String
'Dim X As Integer
'For X = 0 To UBound(zz)
' zz(X) = DV_APC.Item(X).Item(1).ToString
'Next

'Select Case LCase(control.Id)
' Case Is = "apcat"
' GetItemLabel = zz(index)
'End Select
''Dim zz(6) As String
zz(0) = "0"
zz(1) = "1"
zz(2) = "2"
zz(3) = "3"
zz(4) = "4"
zz(5) = "5"

GetItemLabel = index.ToString
MsgBox(DV_APC.Count)
End Function

Public Function GetItemID(ByVal control As IRibbonControl, ByVal index
As Integer) As String
GetItemID = control.Id.ToString + index.ToString
End Function


I tried various ways to get the DV_APC (dataview of a table) data into the
ribbon
one that has been delete is in GetItemLabel
GetItemLabel = DV_APC.item(index).item(1).tostring

When that didn't work I though maybe the data had to be in an array which is
what you see above

the MSGBOX in GetItemsLabel shows a 0 for each request (number of which is
determined by GetItemCount) when I attempt to access the dropDown and only
when I attempt to access the dropDown (not at word startup)


Patrick Schmid said:
Can you show your RibbonX code?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

I am using Word 2007, VSTO2005SE and Visual Studio VB to create a shared
addin automation app.

I have an "other" app that launches Word calling a particular Sub in my dotm
file

The dotm declares the addin like this "Public MCTai As New MCTClass07.Class07"

The dotm calls Class07 routines that load Class07 tables from SQL. This call
resides in the routine called by the "other" app

Subs executed from the dotm that display table.row.count show that these
tables have data

I have created Tabs in the Ribbon with some success using callbacks for
buttons to the .net code

The problem starts when I try to populate a dropDown with data from these
local tables

I can populate the dropDown with static data in the GetItemCount,
GetItemLabel and GetItemID functions

When I replace the static data with table information like GetItemLabel =
DV_APC.Item(X).Item(1).ToString, I get error messages NOT when Word starts
but when I try to select the dropDown. The error messages indicate there is
no data in DV_APC

When I put a MSGBOX for the table.row.count of a table in the GetItemLable
function, it displays 0 rows

The core of the dotm looks like this

Public WithEvents appWord As Word.Application
Public MCTai As New MCTClass07.Class07

Public Function MSGatewayInitialize(OdbcStr As String, LibName As String,
recordID As Long, docName As String, ByRef rcMsg As String) As Long
Dim returnCode As Long

returnCode = 0
Call Register_Event_Handler(OdbcStr) 'add event handler

On Error GoTo init_error

Call MCTai.InitDocument(ActiveDocument, OdbcStr, LibName, recordID)
Call Module1.KeepData(OdbcStr, LibName) 'this call will save data to
MCTai and load tables from SQL

On Error GoTo 0
MSGatewayInitialize = returnCode
Exit Function

init_error:
MsgBox (Err.Description) + vbCrLf + "Initialization error"
Err.Clear
returnCode = -1

End Function

So my question may be "What is the order of these parts loading"?

Or my question may be "how do I read SQL tables into the dropDowns of the
ribbon since I have to make the queries to SQL from my code"?
 
S

slaprade

I appreciate your response

Are you indicating that a dataview canNOT be used here?

The dataview is declared at the top of the .net code. I placed a msgbox in
the GetItemLable to show the dataview.count which indicates 0 as many times
as I have specified in the GetItemCount. The problem seems to be getting the
dataview populated before the ribbon or a finding a way to reload the ribbon
after the dataview is populated


The sub that is called by my "other app" has a call to the .net code that
loads the dataview but it seems that is to late for the ribbon

What is rerally wierd is that when word starts and the riibon is right there
up on the screen, there is no indication that anything is wrong. It is not
until I click on the dropDown that I get the displays from the MSGBOX that I
placed in the GetItemLable routine

So if the ribbon has already run the GetItemLabel code by the time I see the
ribbon, why didn't I get the msgbox displays then?

IS there a way to reload the ribbon after start has completed. I read
something somewhere about "deactivate" or "devalidate" or something like
that.

Patrick Schmid said:
I think there might be some misunderstanding as to how this works.
Office first calls GetItemCount to determine how many items there are in
the dropdown. Then it will call GetItemLabel for every single one of
those items. So if you give it a count of 4, GetItemLabel will be called
four times. The index that is passed into the method is a simple
zero-based index. So the first one is 0, second 1, etc.
The other thing you should check is whether the dataview is even defined
at this point in time.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

sure - here is the ribbon XML

<group id="MCTCat" label="Categories" >
<dropDown id="APCat"
getItemCount="GetItemCount"
getItemID="GetItemID"
getItemLabel="GetItemLabel"/>
<dropDown id="ChooseDepartment" label="AP Cat">
<item id="Dept1" label="Shipping" />
<item id="Dept2" label="Accounting"/>
<item id="Dept3" label="Engineering" />
</dropDown>
</group>

and the .net code

Public Function GetItemCount(ByVal control As IRibbonControl) As Integer
Select Case LCase(control.Id)
Case Is = "apcat"
GetItemCount = 4
End Select
End Function

Public Function GetItemLabel(ByVal control As IRibbonControl, ByVal
index As Integer) As String
Dim zz(6) As String
'Dim X As Integer
'For X = 0 To UBound(zz)
' zz(X) = DV_APC.Item(X).Item(1).ToString
'Next

'Select Case LCase(control.Id)
' Case Is = "apcat"
' GetItemLabel = zz(index)
'End Select
''Dim zz(6) As String
zz(0) = "0"
zz(1) = "1"
zz(2) = "2"
zz(3) = "3"
zz(4) = "4"
zz(5) = "5"

GetItemLabel = index.ToString
MsgBox(DV_APC.Count)
End Function

Public Function GetItemID(ByVal control As IRibbonControl, ByVal index
As Integer) As String
GetItemID = control.Id.ToString + index.ToString
End Function


I tried various ways to get the DV_APC (dataview of a table) data into the
ribbon
one that has been delete is in GetItemLabel
GetItemLabel = DV_APC.item(index).item(1).tostring

When that didn't work I though maybe the data had to be in an array which is
what you see above

the MSGBOX in GetItemsLabel shows a 0 for each request (number of which is
determined by GetItemCount) when I attempt to access the dropDown and only
when I attempt to access the dropDown (not at word startup)


Patrick Schmid said:
Can you show your RibbonX code?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed


I am using Word 2007, VSTO2005SE and Visual Studio VB to create a shared
addin automation app.

I have an "other" app that launches Word calling a particular Sub in my dotm
file

The dotm declares the addin like this "Public MCTai As New MCTClass07.Class07"

The dotm calls Class07 routines that load Class07 tables from SQL. This call
resides in the routine called by the "other" app

Subs executed from the dotm that display table.row.count show that these
tables have data

I have created Tabs in the Ribbon with some success using callbacks for
buttons to the .net code

The problem starts when I try to populate a dropDown with data from these
local tables

I can populate the dropDown with static data in the GetItemCount,
GetItemLabel and GetItemID functions

When I replace the static data with table information like GetItemLabel =
DV_APC.Item(X).Item(1).ToString, I get error messages NOT when Word starts
but when I try to select the dropDown. The error messages indicate there is
no data in DV_APC

When I put a MSGBOX for the table.row.count of a table in the GetItemLable
function, it displays 0 rows

The core of the dotm looks like this

Public WithEvents appWord As Word.Application
Public MCTai As New MCTClass07.Class07

Public Function MSGatewayInitialize(OdbcStr As String, LibName As String,
recordID As Long, docName As String, ByRef rcMsg As String) As Long
Dim returnCode As Long

returnCode = 0
Call Register_Event_Handler(OdbcStr) 'add event handler

On Error GoTo init_error

Call MCTai.InitDocument(ActiveDocument, OdbcStr, LibName, recordID)
Call Module1.KeepData(OdbcStr, LibName) 'this call will save data to
MCTai and load tables from SQL

On Error GoTo 0
MSGatewayInitialize = returnCode
Exit Function

init_error:
MsgBox (Err.Description) + vbCrLf + "Initialization error"
Err.Clear
returnCode = -1

End Function

So my question may be "What is the order of these parts loading"?

Or my question may be "how do I read SQL tables into the dropDowns of the
ribbon since I have to make the queries to SQL from my code"?
 
P

Patrick Schmid [MVP]

I am not indicating anything. Reading your reply, your problem really
seems to be getting to the DataView. The two callbacks that populate the
dropdown are not executed until you click the dropdown for the first
time.
You can't reload the ribbon. That only works by unloading and reloading
the add-in, which is not an option in your case. You can force the two
callbacks to be executed again by using invalidate, but I don't think
this is going to help you.
Have you run this add-in in debug mode in VS already to see what is
going on with the dataview here?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

I appreciate your response

Are you indicating that a dataview canNOT be used here?

The dataview is declared at the top of the .net code. I placed a msgbox in
the GetItemLable to show the dataview.count which indicates 0 as many times
as I have specified in the GetItemCount. The problem seems to be getting the
dataview populated before the ribbon or a finding a way to reload the ribbon
after the dataview is populated


The sub that is called by my "other app" has a call to the .net code that
loads the dataview but it seems that is to late for the ribbon

What is rerally wierd is that when word starts and the riibon is right there
up on the screen, there is no indication that anything is wrong. It is not
until I click on the dropDown that I get the displays from the MSGBOX that I
placed in the GetItemLable routine

So if the ribbon has already run the GetItemLabel code by the time I see the
ribbon, why didn't I get the msgbox displays then?

IS there a way to reload the ribbon after start has completed. I read
something somewhere about "deactivate" or "devalidate" or something like
that.

Patrick Schmid said:
I think there might be some misunderstanding as to how this works.
Office first calls GetItemCount to determine how many items there are in
the dropdown. Then it will call GetItemLabel for every single one of
those items. So if you give it a count of 4, GetItemLabel will be called
four times. The index that is passed into the method is a simple
zero-based index. So the first one is 0, second 1, etc.
The other thing you should check is whether the dataview is even defined
at this point in time.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

sure - here is the ribbon XML

<group id="MCTCat" label="Categories" >
<dropDown id="APCat"
getItemCount="GetItemCount"
getItemID="GetItemID"
getItemLabel="GetItemLabel"/>
<dropDown id="ChooseDepartment" label="AP Cat">
<item id="Dept1" label="Shipping" />
<item id="Dept2" label="Accounting"/>
<item id="Dept3" label="Engineering" />
</dropDown>
</group>

and the .net code

Public Function GetItemCount(ByVal control As IRibbonControl) As Integer
Select Case LCase(control.Id)
Case Is = "apcat"
GetItemCount = 4
End Select
End Function

Public Function GetItemLabel(ByVal control As IRibbonControl, ByVal
index As Integer) As String
Dim zz(6) As String
'Dim X As Integer
'For X = 0 To UBound(zz)
' zz(X) = DV_APC.Item(X).Item(1).ToString
'Next

'Select Case LCase(control.Id)
' Case Is = "apcat"
' GetItemLabel = zz(index)
'End Select
''Dim zz(6) As String
zz(0) = "0"
zz(1) = "1"
zz(2) = "2"
zz(3) = "3"
zz(4) = "4"
zz(5) = "5"

GetItemLabel = index.ToString
MsgBox(DV_APC.Count)
End Function

Public Function GetItemID(ByVal control As IRibbonControl, ByVal index
As Integer) As String
GetItemID = control.Id.ToString + index.ToString
End Function


I tried various ways to get the DV_APC (dataview of a table) data into the
ribbon
one that has been delete is in GetItemLabel
GetItemLabel = DV_APC.item(index).item(1).tostring

When that didn't work I though maybe the data had to be in an array which is
what you see above

the MSGBOX in GetItemsLabel shows a 0 for each request (number of which is
determined by GetItemCount) when I attempt to access the dropDown and only
when I attempt to access the dropDown (not at word startup)


:

Can you show your RibbonX code?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed


I am using Word 2007, VSTO2005SE and Visual Studio VB to create a shared
addin automation app.

I have an "other" app that launches Word calling a particular Sub in my dotm
file

The dotm declares the addin like this "Public MCTai As New MCTClass07.Class07"

The dotm calls Class07 routines that load Class07 tables from SQL. This call
resides in the routine called by the "other" app

Subs executed from the dotm that display table.row.count show that these
tables have data

I have created Tabs in the Ribbon with some success using callbacks for
buttons to the .net code

The problem starts when I try to populate a dropDown with data from these
local tables

I can populate the dropDown with static data in the GetItemCount,
GetItemLabel and GetItemID functions

When I replace the static data with table information like GetItemLabel =
DV_APC.Item(X).Item(1).ToString, I get error messages NOT when Word starts
but when I try to select the dropDown. The error messages indicate there is
no data in DV_APC

When I put a MSGBOX for the table.row.count of a table in the GetItemLable
function, it displays 0 rows

The core of the dotm looks like this

Public WithEvents appWord As Word.Application
Public MCTai As New MCTClass07.Class07

Public Function MSGatewayInitialize(OdbcStr As String, LibName As String,
recordID As Long, docName As String, ByRef rcMsg As String) As Long
Dim returnCode As Long

returnCode = 0
Call Register_Event_Handler(OdbcStr) 'add event handler

On Error GoTo init_error

Call MCTai.InitDocument(ActiveDocument, OdbcStr, LibName, recordID)
Call Module1.KeepData(OdbcStr, LibName) 'this call will save data to
MCTai and load tables from SQL

On Error GoTo 0
MSGatewayInitialize = returnCode
Exit Function

init_error:
MsgBox (Err.Description) + vbCrLf + "Initialization error"
Err.Clear
returnCode = -1

End Function

So my question may be "What is the order of these parts loading"?

Or my question may be "how do I read SQL tables into the dropDowns of the
ribbon since I have to make the queries to SQL from my code"?
 
S

slaprade

I'm sorry, I meant no offense, I'm just trying to understand

I wrote a Word macros that call a .net sub that reports the row count in DV
I put back the msgbox in the GetItemLabel in .vb that reports the DV count

After loading the record from my "other app" I run the Word macro and it
reports 14 items in DV

When I click on my tab , I get 4 msgbox each displaying 0

Interestingly, I also wrote a Word macro
msgbox(MCTai.DV_APC.count)

which returns an error indicating an "Object is Required"

So It seems that Word doesn't know about the declarations made in .net (.vb
code) which looks like this

imports Extensibility
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop
Imports System.Data
Imports Microsoft.Office.Core
Imports Word = Microsoft.Office.Interop.Word

<GuidAttribute("8FF8BA64-1135-4282-80AD-13C28F2C342D"),
ProgIdAttribute("MCTClass07.Connect")> _

Public Class Class07

Implements Extensibility.IDTExtensibility2, IRibbonExtensibility

Public ThisApplication As Word.Application
Dim addInInstance As Object
Public ThisDoc As Word.Document
Public UInfo As New Hashtable
Public LibName As String
Public OtherStr As String


Public DV_APP As New DataView
Public DV_APC As New DataView
Public DV_SEC As New DataView
Public DV_APM As New DataView
Public DV_BAS As New DataView
Public DV_ProdCode As DataView


Is the question "how do I get Word to recognize the .net declarations?"

Word obviously knows about .net because I can call .net routines







Patrick Schmid said:
I am not indicating anything. Reading your reply, your problem really
seems to be getting to the DataView. The two callbacks that populate the
dropdown are not executed until you click the dropdown for the first
time.
You can't reload the ribbon. That only works by unloading and reloading
the add-in, which is not an option in your case. You can force the two
callbacks to be executed again by using invalidate, but I don't think
this is going to help you.
Have you run this add-in in debug mode in VS already to see what is
going on with the dataview here?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

I appreciate your response

Are you indicating that a dataview canNOT be used here?

The dataview is declared at the top of the .net code. I placed a msgbox in
the GetItemLable to show the dataview.count which indicates 0 as many times
as I have specified in the GetItemCount. The problem seems to be getting the
dataview populated before the ribbon or a finding a way to reload the ribbon
after the dataview is populated


The sub that is called by my "other app" has a call to the .net code that
loads the dataview but it seems that is to late for the ribbon

What is rerally wierd is that when word starts and the riibon is right there
up on the screen, there is no indication that anything is wrong. It is not
until I click on the dropDown that I get the displays from the MSGBOX that I
placed in the GetItemLable routine

So if the ribbon has already run the GetItemLabel code by the time I see the
ribbon, why didn't I get the msgbox displays then?

IS there a way to reload the ribbon after start has completed. I read
something somewhere about "deactivate" or "devalidate" or something like
that.

Patrick Schmid said:
I think there might be some misunderstanding as to how this works.
Office first calls GetItemCount to determine how many items there are in
the dropdown. Then it will call GetItemLabel for every single one of
those items. So if you give it a count of 4, GetItemLabel will be called
four times. The index that is passed into the method is a simple
zero-based index. So the first one is 0, second 1, etc.
The other thing you should check is whether the dataview is even defined
at this point in time.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed


sure - here is the ribbon XML

<group id="MCTCat" label="Categories" >
<dropDown id="APCat"
getItemCount="GetItemCount"
getItemID="GetItemID"
getItemLabel="GetItemLabel"/>
<dropDown id="ChooseDepartment" label="AP Cat">
<item id="Dept1" label="Shipping" />
<item id="Dept2" label="Accounting"/>
<item id="Dept3" label="Engineering" />
</dropDown>
</group>

and the .net code

Public Function GetItemCount(ByVal control As IRibbonControl) As Integer
Select Case LCase(control.Id)
Case Is = "apcat"
GetItemCount = 4
End Select
End Function

Public Function GetItemLabel(ByVal control As IRibbonControl, ByVal
index As Integer) As String
Dim zz(6) As String
'Dim X As Integer
'For X = 0 To UBound(zz)
' zz(X) = DV_APC.Item(X).Item(1).ToString
'Next

'Select Case LCase(control.Id)
' Case Is = "apcat"
' GetItemLabel = zz(index)
'End Select
''Dim zz(6) As String
zz(0) = "0"
zz(1) = "1"
zz(2) = "2"
zz(3) = "3"
zz(4) = "4"
zz(5) = "5"

GetItemLabel = index.ToString
MsgBox(DV_APC.Count)
End Function

Public Function GetItemID(ByVal control As IRibbonControl, ByVal index
As Integer) As String
GetItemID = control.Id.ToString + index.ToString
End Function


I tried various ways to get the DV_APC (dataview of a table) data into the
ribbon
one that has been delete is in GetItemLabel
GetItemLabel = DV_APC.item(index).item(1).tostring

When that didn't work I though maybe the data had to be in an array which is
what you see above

the MSGBOX in GetItemsLabel shows a 0 for each request (number of which is
determined by GetItemCount) when I attempt to access the dropDown and only
when I attempt to access the dropDown (not at word startup)


:

Can you show your RibbonX code?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed


I am using Word 2007, VSTO2005SE and Visual Studio VB to create a shared
addin automation app.

I have an "other" app that launches Word calling a particular Sub in my dotm
file

The dotm declares the addin like this "Public MCTai As New MCTClass07.Class07"

The dotm calls Class07 routines that load Class07 tables from SQL. This call
resides in the routine called by the "other" app

Subs executed from the dotm that display table.row.count show that these
tables have data

I have created Tabs in the Ribbon with some success using callbacks for
buttons to the .net code

The problem starts when I try to populate a dropDown with data from these
local tables

I can populate the dropDown with static data in the GetItemCount,
GetItemLabel and GetItemID functions

When I replace the static data with table information like GetItemLabel =
DV_APC.Item(X).Item(1).ToString, I get error messages NOT when Word starts
but when I try to select the dropDown. The error messages indicate there is
no data in DV_APC

When I put a MSGBOX for the table.row.count of a table in the GetItemLable
function, it displays 0 rows

The core of the dotm looks like this

Public WithEvents appWord As Word.Application
Public MCTai As New MCTClass07.Class07

Public Function MSGatewayInitialize(OdbcStr As String, LibName As String,
recordID As Long, docName As String, ByRef rcMsg As String) As Long
Dim returnCode As Long

returnCode = 0
Call Register_Event_Handler(OdbcStr) 'add event handler

On Error GoTo init_error

Call MCTai.InitDocument(ActiveDocument, OdbcStr, LibName, recordID)
Call Module1.KeepData(OdbcStr, LibName) 'this call will save data to
MCTai and load tables from SQL

On Error GoTo 0
MSGatewayInitialize = returnCode
Exit Function

init_error:
MsgBox (Err.Description) + vbCrLf + "Initialization error"
Err.Clear
returnCode = -1

End Function

So my question may be "What is the order of these parts loading"?

Or my question may be "how do I read SQL tables into the dropDowns of the
ribbon since I have to make the queries to SQL from my code"?
 
S

slaprade

I haven't been able to trace in debug from Word into .net. If I put a break
in a Word Macro that calls .net then Word stops at the call. Attempting to
step into the .net just performs whatever the .net does and skips to the next
line in Word's macro
I read someting about being able to set debug mode to allow tracing through
..net but I was unable to find the setting in VS2005. I would love to know how
to do it if you can offer suggestions on how to make that happen



Patrick Schmid said:
I am not indicating anything. Reading your reply, your problem really
seems to be getting to the DataView. The two callbacks that populate the
dropdown are not executed until you click the dropdown for the first
time.
You can't reload the ribbon. That only works by unloading and reloading
the add-in, which is not an option in your case. You can force the two
callbacks to be executed again by using invalidate, but I don't think
this is going to help you.
Have you run this add-in in debug mode in VS already to see what is
going on with the dataview here?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

I appreciate your response

Are you indicating that a dataview canNOT be used here?

The dataview is declared at the top of the .net code. I placed a msgbox in
the GetItemLable to show the dataview.count which indicates 0 as many times
as I have specified in the GetItemCount. The problem seems to be getting the
dataview populated before the ribbon or a finding a way to reload the ribbon
after the dataview is populated


The sub that is called by my "other app" has a call to the .net code that
loads the dataview but it seems that is to late for the ribbon

What is rerally wierd is that when word starts and the riibon is right there
up on the screen, there is no indication that anything is wrong. It is not
until I click on the dropDown that I get the displays from the MSGBOX that I
placed in the GetItemLable routine

So if the ribbon has already run the GetItemLabel code by the time I see the
ribbon, why didn't I get the msgbox displays then?

IS there a way to reload the ribbon after start has completed. I read
something somewhere about "deactivate" or "devalidate" or something like
that.

Patrick Schmid said:
I think there might be some misunderstanding as to how this works.
Office first calls GetItemCount to determine how many items there are in
the dropdown. Then it will call GetItemLabel for every single one of
those items. So if you give it a count of 4, GetItemLabel will be called
four times. The index that is passed into the method is a simple
zero-based index. So the first one is 0, second 1, etc.
The other thing you should check is whether the dataview is even defined
at this point in time.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed


sure - here is the ribbon XML

<group id="MCTCat" label="Categories" >
<dropDown id="APCat"
getItemCount="GetItemCount"
getItemID="GetItemID"
getItemLabel="GetItemLabel"/>
<dropDown id="ChooseDepartment" label="AP Cat">
<item id="Dept1" label="Shipping" />
<item id="Dept2" label="Accounting"/>
<item id="Dept3" label="Engineering" />
</dropDown>
</group>

and the .net code

Public Function GetItemCount(ByVal control As IRibbonControl) As Integer
Select Case LCase(control.Id)
Case Is = "apcat"
GetItemCount = 4
End Select
End Function

Public Function GetItemLabel(ByVal control As IRibbonControl, ByVal
index As Integer) As String
Dim zz(6) As String
'Dim X As Integer
'For X = 0 To UBound(zz)
' zz(X) = DV_APC.Item(X).Item(1).ToString
'Next

'Select Case LCase(control.Id)
' Case Is = "apcat"
' GetItemLabel = zz(index)
'End Select
''Dim zz(6) As String
zz(0) = "0"
zz(1) = "1"
zz(2) = "2"
zz(3) = "3"
zz(4) = "4"
zz(5) = "5"

GetItemLabel = index.ToString
MsgBox(DV_APC.Count)
End Function

Public Function GetItemID(ByVal control As IRibbonControl, ByVal index
As Integer) As String
GetItemID = control.Id.ToString + index.ToString
End Function


I tried various ways to get the DV_APC (dataview of a table) data into the
ribbon
one that has been delete is in GetItemLabel
GetItemLabel = DV_APC.item(index).item(1).tostring

When that didn't work I though maybe the data had to be in an array which is
what you see above

the MSGBOX in GetItemsLabel shows a 0 for each request (number of which is
determined by GetItemCount) when I attempt to access the dropDown and only
when I attempt to access the dropDown (not at word startup)


:

Can you show your RibbonX code?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed


I am using Word 2007, VSTO2005SE and Visual Studio VB to create a shared
addin automation app.

I have an "other" app that launches Word calling a particular Sub in my dotm
file

The dotm declares the addin like this "Public MCTai As New MCTClass07.Class07"

The dotm calls Class07 routines that load Class07 tables from SQL. This call
resides in the routine called by the "other" app

Subs executed from the dotm that display table.row.count show that these
tables have data

I have created Tabs in the Ribbon with some success using callbacks for
buttons to the .net code

The problem starts when I try to populate a dropDown with data from these
local tables

I can populate the dropDown with static data in the GetItemCount,
GetItemLabel and GetItemID functions

When I replace the static data with table information like GetItemLabel =
DV_APC.Item(X).Item(1).ToString, I get error messages NOT when Word starts
but when I try to select the dropDown. The error messages indicate there is
no data in DV_APC

When I put a MSGBOX for the table.row.count of a table in the GetItemLable
function, it displays 0 rows

The core of the dotm looks like this

Public WithEvents appWord As Word.Application
Public MCTai As New MCTClass07.Class07

Public Function MSGatewayInitialize(OdbcStr As String, LibName As String,
recordID As Long, docName As String, ByRef rcMsg As String) As Long
Dim returnCode As Long

returnCode = 0
Call Register_Event_Handler(OdbcStr) 'add event handler

On Error GoTo init_error

Call MCTai.InitDocument(ActiveDocument, OdbcStr, LibName, recordID)
Call Module1.KeepData(OdbcStr, LibName) 'this call will save data to
MCTai and load tables from SQL

On Error GoTo 0
MSGatewayInitialize = returnCode
Exit Function

init_error:
MsgBox (Err.Description) + vbCrLf + "Initialization error"
Err.Clear
returnCode = -1

End Function

So my question may be "What is the order of these parts loading"?

Or my question may be "how do I read SQL tables into the dropDowns of the
ribbon since I have to make the queries to SQL from my code"?
 

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