I have a form that when starting must fill certain ComboBox, I have problems with some in particular, which are filled from a function that invokes data from SQL SERVER. The issue is that when I put the Call llenarInstrumentos(cmbCVinstr)
statement in the Initialize
event and I do the Load
of the form, I get the following error:
Se ha producido el error -2147352571(800200005) en tiempo de ejecución:
No se puede configurar la propiedad List. Los tipos no coinciden
It's worth saying that cmbCVinstr
is an example of the comboboxes that use this routine. The connection to the server is done separately and is independent of this form, so the problem is the latter. This connection is used for other forms and similar routines correctly feed those forms, the main difference is that those forms that do work are a single column but I do not know if that has something to do with not recognizing the combobox.
Finally, making tests with that event (deleting and adding the command) I realized that the problem is that routine specifically because outside of it everything runs normally.
The code of the function is:
Sub llenarInstrumentos(ByVal cb As ComboBox)
instrumentos = "SELECT * FROM [pruebaEDGE].[dbo].[InstrumentosPiP] ORDER BY [TdValor] ASC"
Set rs = CreateObject("ADODB.recordset")
rs.Open instrumentos, cn
If Not rs.EOF Then
i = 0
cb.ColumnCount = 3
cb.ColumnWidths = "210 pt;0 pt;0 pt"
Do Until rs.EOF
With cb
.AddItem rs.Fields("Descrip") & " (" & rs.Fields("TdValor") & ")", i
.List(i, 1) = rs.Fields("Tipo")
.List(i, 2) = rs.Fields("Id")
End With
i = i + 1
rs.movenext
Loop
End If
rs.Close
Set rs = Nothing
End Sub