I am new to the whole concept of "data binding". What I am trying to do seems very simple, but I don't know where to start. I have a database with an ODBC System DSN and I can connect to it with an ADODB.Connection object. I can also create an ADODB.Recordset object and traverse/manipulate the records contained in it. What I am unable to do is bind a listbox to this recordset. I know I could simply create code to traverse both the listbox and the recordset to copy recordset data to the listbox and remove listbox entries that are not in the recordset, but this is not a trivial task. Clearing the listbox and repopulating is easy enough, but doing this will reset the selected list item every time, and this is unacceptable. Any suggestions?

By the way, I am using VB 6.0

Set Rs = Nothing
Rs.open " Select * From Table Where Cond ...",Con,adOpenStatic
if Rs.Recordcount > 0 then
   rs.movefirst
  do while not rs.eof
    list1.Additem rs.fields("Field1")
    rs.movenext
  loop
end if

Thanks,

I have to create list of item which are selected in list box like
" a,b,c,d,e,f " How can I do ? it can be in a string .

I have to create list of item which are selected in list box like
" a,b,c,d,e,f " How can I do ? it can be in a string .

Very aware that this thread is dated, but ran across it and thought I'd post for anyone else who comes along.

A more practical way is to use DAO instead of ADODB.

Dim rsStudID As DAO.Recordset
Set rsStudID = CurrentDb.OpenRecordset("SELECT studentID FROM applications WHERE inactive=0")
Set liststudID.Recordset = rsStudID

This will populate the liststudID List Box with source type "Table/Query" with the data very quickly.

This article has been dead for over six months. Start a new discussion instead.