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.

9. Click on the down arrow to the right of the Settings box <strong>and</strong> select datCities.<br />

10. Select the DataField property <strong>and</strong> click on the down arrow at the right of the<br />

Settings box.<br />

You will see the names of the different fields in the table.<br />

11. Select the field city.<br />

The text box now is said to be bound to the data control. It can now display data<br />

from the city field of the Cities table.<br />

12. Place another text box, txtPop1995, on the form.<br />

13. Select txtPop1995’s DataSource property.<br />

14. Click on the down arrow to the right of the Settings box <strong>and</strong> select datCities.<br />

15. Select the DataField property, click on the down arrow at the right of the Settings<br />

box, <strong>and</strong> select pop1995.<br />

16. Run the program.<br />

The form will appear as in Figure 11-1. The arrows on the data control, called<br />

navigation arrows, look <strong>and</strong> act like VCR buttons. The arrows have been identified<br />

by the tasks they perform.<br />

17. Click on the various navigation arrows on the data control to see the different<br />

cities <strong>and</strong> their populations in the Cities table displayed in the text boxes.<br />

18. Change the name of a city or change its population <strong>and</strong> then move to another<br />

record.<br />

If you look back through the records, you will see that the data have been permanently<br />

changed.<br />

FIGURE 11-1 A Data Control with Two Text Boxes Bound to It<br />

■ USING CODE WITH A DATA CONTROL<br />

Only one record can be accessed at a time; this record is called the current record. In this walkthrough,<br />

the text boxes bound to the data control showed the contents of the city <strong>and</strong> pop1995<br />

fields of the current record. The user clicked on the navigation arrows of the data control to<br />

select a new current record.<br />

Code can be used to designate another record as the current record. The methods<br />

MoveNext, MovePrevious, MoveLast, <strong>and</strong> MoveFirst select a new current record as suggested<br />

by their names. For instance, the statement<br />

Data1.Recordset.MoveLast<br />

specifies the last record of the table to be the current record. (The word Recordset is inserted<br />

in most data-control statements that manipulate records for reasons that needn’t concern us<br />

now.)<br />

The entry of the field fieldName of the current record is<br />

Data1.Recordset.Fields(“fieldName”).Value<br />

For instance, with the status as in Figure 11-1, the statement<br />

strVar = datCities.Recordset.Fields(“city”).Value<br />

An Introduction to Databases 325

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

Saved successfully!

Ooh no, something went wrong!