I am not fond of data binding as a rule for several reasons.
My suggestion would be to open a recordset forward only and read only, then loop through the recordset using the additem method
This example uses a SQL Server stored procedure that receives input parameters and returns a record set so it is a bit more complex than just using a simple select but should give you the idea.
Note: the Data Base connection is already open. Depending on your app you may want to do that differently
Private Sub FillCboCombo()
Dim Rs As New ADODB.Recordset
Dim strS As String
Dim cmd As New Command
Dim Param As New Parameter
'note: although there is a less verbose means of doing this code, the less verbose method fails when attempting to open a recordset. You must use this syntax when returning a
'value from a stored procedure
With cmd
.CommandText = "sp_FillCombo"
.CommandType = adCmdStoredProc
.ActiveConnection = DBConn
Set Rs = .Execute
End With
Do While Not Rs.EOF And Not Rs.BOF
cboTable.AddItem Rs!NameOfColumn
Rs.MoveNext
Loop
cboComb0.Text = cboCombo.List(0)
Set Rs = Nothing
The trouble with data binding is that you have to trust Microsoft to have it work properly. Meaning many hours researching workarounds in forums like these. I prefer to go as low level as possible because I trust my code more than theirs. At least it's easier to debug. For example, if you use the DataRepeater control, you HAVE to use data binding. There's a bug in it that causes it to fail to place your pointer in the right places in some cases, and the workaround is to bind an additional ADODC control to it.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.