External Data in a ComboBox

Started by davidgon, December 14, 2016, 01:56:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

davidgon

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

Thomas Winkel

#1
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

davidgon

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

Thomas Winkel

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.

davidgon

Thanks

When I go back to work after Christmas I'll try

davidgon

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