19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

340 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

End If<br />

End Sub<br />

Private Sub Form_Load()<br />

msgCities.ColWidth(0) = 1000 ‘Widen the first column slightly<br />

End Sub<br />

[Run]<br />

[Click on the comm<strong>and</strong> button.]<br />

■ USING THE DATA-BOUND LIST BOX AND COMBO BOX CONTROLS<br />

The data-bound list box <strong>and</strong> data-bound combo box controls look like the st<strong>and</strong>ard list box <strong>and</strong><br />

combo box controls. They are often used with data-entry forms to speed data entry <strong>and</strong> ensure<br />

that valid data is entered. These controls automatically fill with a column from a table or<br />

recordset after you set a few properties. Note that the data-bound controls display data from<br />

a table or a recordset. Therefore, three methods (AddItem, Clear, <strong>and</strong> RemoveItem) <strong>and</strong> two<br />

properties (ListCount <strong>and</strong> Sorted) used with the regular list box <strong>and</strong> combo box are not available<br />

with the data-bound controls. The count of items displayed in a data-bound control is determined<br />

by the RecordCount property of the recordset.<br />

Two key properties determine the entries of a data-bound list or combo box—Row-<br />

Source <strong>and</strong> ListField. RowSource specifies a data control, <strong>and</strong> ListField specifies a field<br />

from the data control’s table or recordset. That field will be used to fill the list.<br />

EXAMPLE 2<br />

The data-bound list box in the following example displays the countries in the Countries table of<br />

MEGACTY2.MDB. When the comm<strong>and</strong> button is clicked, SQL is used to sort the countries by their 1995

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!