Binding Data to Controls with MS Access and ADO - Displaying the combo box
(Page 5 of 6 )
When the form is displayed the combo box will be empty, but when the "Populate Combobox" button is clicked, the combo box will be filled with the names of the shippers in the database as shown. For the purposes of this display, the form's record navigator, separator and record related properties have been set to false.

Filling a list box
For read-only decision support data display purposes, the list box is ideal. It is very efficient in terms of resources, and it is easy to add functionality to arrange for drill-down of data -- more refined filtering of the data. Similar to the combo box, in this demo tutorial, add a list box and a button. For the click event of the button, type in this code.
Private Sub Command11_Click()
Me.List12.RowSource = ""
'-----fast data retrieval block----
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open "C:Program FilesMicrosoft OfficeOFFICE11SAMPLESNorthwind.mdb"
End With
strsql = "Select * from Shippers"
With rst
Set .ActiveConnection = cnn
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Open strsql
End With
'-----------------------
Dim strlist
strlist = ""
rst.MoveFirst
While Not rst.EOF
'---------create value list
strlist = strlist & rst.Fields.Item(1) + "--" + rst.Fields.Item(2) & ";"
rst.MoveNext
Wend
MsgBox strlist
Me!List12.RowSource = strlist
Set rst = Nothing
Set cnn = Nothing
End Sub
The design view of the list box control is shown. The list will be filled when the "Populate the List Box" button is clicked. It is necessary that the Row source type property be set to value list at design time for the list box.

Next: Displaying a list box >>
More ASP.NET Articles
More By Jayaram Krishnaswamy