Chris's Event Programming with Visual Basic course.
Contents
| Introduction | Tool Bars & Control Arrays |
Open a new project and paste a data control
and two text boxes (not in an array) to the form so that it appears as
below;
the data control is unusual in that it’s
purpose is to attach or bind data to the form on which it is placed. Select
it’s DataBaseName property and click on the three dots. This provides a
method of navigating to the required database, here we will use the Biblio.mdb
database seen earlier. Next select the RecordSource property, this enables
the required table to be accessed from the database. Here select Titles.
We have now bound our required data to the form.
The Text box is a data - aware component,
the other standard ones supplied with VB3 are Check box
Image
Label
Picture box &
Text box.
Make the DataSource property on each of
the text boxes Data1, for Text1 make DataField Title (selected from a list
associated via the data bound to Data1) and on Text2 make DataField ISDN.
If the application is now ran, the data in the database can be accessed,
it is navigated through the Data control navigation buttons. Existing entries
may be amended by changing the contents of the text boxes. New entries
may also be made to the database table, however, to do this a method, AddNew
needs to be invoked, this operates on the RecordSet property of the data.
Place a command button on the form with the caption ‘New’ so that it appears
as below;
change the code for the click event
of this new control so that it appears as:-
Sub Command1_Click ()
data1.Recordset.AddNew
End Sub
If the application is now run, new entries
can be made to the underlying record set.
Visual Basic and all other Microsoft products mentioned
in this series are trademarks of the Microsoft Corporation.