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
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
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
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.
Thanks
When I go back to work after Christmas I'll try
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