Just Iterate through the
Records in a Table


by Rick Meyer




1. Start a new standard exe.
2. On Form1 put a data control named Data1.
3. On Form1 put 3 Textboxes.
4. On Form1 put an OLE.
    (when the insert object window appears, just click cancel.)

      Form1 should look like the picture above.

Installed with Visual Basic is a demo Northwind database. It should be in your VB directory called Nwind.mdb (mdb is the extension used for an Access database). If you have VB 5.0 then it is at C:\Program Files\DevStudio\VB\Nwind.mdb

So go to the Properties Window and select Data1. Find the property called DatabaseName. When you click the tab you will be allowed to browse to find a database. Choose - C:\Program Files\DevStudio\VB\Nwind.mdb or your location of the Northwind database.

Access includes all its tables in a single file. Since you have choosen a DatabaseName, the Data Control will now be able to provide you with a list with all the tables in it. In this demo we shall display records in the table "Categories".

To do this find the RecordSource property for Data1 and click on the tab. A dropdown list of all the tables in the database will appear. Choose Categories.

Now connect each Textbox and the OLE Control to Data1.

To do this find the DataSource property of each Textbox. Click on the tab and choose the Data1 control from the dropdown list. (VB knows the names of the data controls you placed on the form.) Do the same for the OLE Control.

Now we want to identify each Textbox with a field in the Categories table. Since we have already set the RecordSource to the Categories table for Data1, and connected each Textbox to Data1, VB is able to provide a dropdown list of all the fields in the table named Categories.

You will find this dropdown list in the Textbox property called DataField. So click the tab for each Textbox and choose one of the first three fields for each. Set the Multiline property to True for the Textbox you have chosen for Description. Finally, click the tab in the OLE datafield property and choose the "Picture" field.

That is all there is to it! You don't have to write any code! Run the program and click on the arrow tabs of the Data1 control.

Since the Textboxes and the OLE control are bound to Data1, they are automatically populated according to the Data1 recordsource property and the Textbox datafield property.