Visio Guy

Visio Discussions => Programming & Code => Topic started by: davidgon on December 14, 2016, 01:56:44 PM

Title: External Data in a ComboBox
Post by: davidgon on December 14, 2016, 01:56:44 PM
Hello!

I want to make an userform. I have linked a external data to my document. The cuestion is... How could I make a combobox with the rows of my external data? This is, what do I have to put in RowSource, in the properties of the combobox?

Thanks
Title: Re: External Data in a ComboBox
Post by: Thomas Winkel on December 14, 2016, 08:12:52 PM
Hi,

you have to iterate through all the rows in a DRS and add the value of a row property to the ComboBox:
https://msdn.microsoft.com/en-us/library/office/ff767492.aspx
Title: Re: External Data in a ComboBox
Post by: davidgon on December 16, 2016, 11:07:25 AM
I have tried something like this, but it doesn't work. Where is the problem?

Dim vsoDataRecordset As Visio.DataRecordset
    Dim intCount As Integer
    Dim lngRowIDs() As Long
    Dim lngRow As Long
    Dim lngColumn As Long
    Dim varRowData As Variant
   

    intCount = ThisDocument.DataRecordsets.Count
   

    Set vsoDataRecordset = ThisDocument.DataRecordsets(22)
    lngRowIDs = vsoDataRecordset.GetDataRowIDs("")

    For lngRow = LBound(lngRowIDs) To UBound(lngRowIDs) + 1
        varRowData = vsoDataRecordset.GetRowData(lngRow)
        ComboBox1.AddItem (varRowData)
     
    Next lngRow
Title: Re: External Data in a ComboBox
Post by: Thomas Winkel on December 16, 2016, 02:53:12 PM
Try this:

varRowData = vsoDataRecordset.GetRowData(lngRow)(1)


Or attach a complete example as Visio document (vsd, not vsdx), so that we can reproduce your error without any effort.
Title: Re: External Data in a ComboBox
Post by: davidgon on December 22, 2016, 06:05:50 PM
Thanks

When I go back to work after Christmas I'll try
Title: Re: External Data in a ComboBox
Post by: davidgon on January 19, 2017, 01:32:55 PM
Finally I found the solution:

The problem was that varRowData is an array, not a number, so I couldn't add it to the combobox.

The solution is just to make an iteration throught all the posible values of the array

Dim vsoDataRecordset As Visio.DataRecordset
    Dim intCount As Integer
    Dim lngRowIDs() As Long
    Dim lngRow As Long
    Dim lngColumn As Long
    Dim varRowData As Variant
   

    intCount = ThisDocument.DataRecordsets.Count
   

    Set vsoDataRecordset = ThisDocument.DataRecordsets(22)
    lngRowIDs = vsoDataRecordset.GetDataRowIDs("")

    For lngRow = LBound(lngRowIDs) To UBound(lngRowIDs) + 1
        varRowData = vsoDataRecordset.GetRowData(lngRow)
        For lngColumn = LBound(varRowData) To UBound(varRowData)
        ComboBox1.AddItem (varRowData(lngColumn))
        Next lngColumn
    Next lngRow


Thanks for the help