VB2022 VB2019 VB6 VB Sample Code About Us

Lesson 24 Creating More Advanced Database


In Lesson 23, you have learned how to create a simple database application using data control. However, you could only browse the database using the data control. In this lesson, you shall learn how to create your own navigation buttons for browsing the database. Besides that, we shall also learn how to add, save and delete data.The data control supports some methods that allow manipulation of a database, for example, to move the pointer to a certain location.

The following are some of the commands that you can use to move the pointer around:

' Move to the first record

data_navigator.RecordSet.MoveFirst

' Move to the last record

data_navigator.RecordSet.MoveLast

' Move to the next record

data_navigator.RecordSet.MoveNext

' Move to the first record>

data_navigator.RecordSet.Previous

You can also add, save and delete records using the following commands:

data_navigator.RecordSet.AddNewp  ' Adds a new record

data_navigator.RecordSet.Updatep  ' Updates and saves the new record

data_navigator.RecordSet.Delete  ' Deletes a current record

*note: data_navigator is the name of data control

In the following example, you shall insert four commands and label them as First Record, Next Record, Previous Record and Last Record . They will be used to navigator around the database without using the data control. You still need to retain the same data control (from example in lesson 19) but set the property Visible to no so that users will not see the data control but use the button to browse through the database instead. Now, double-click  on the command button and key in the codes according to the labels.

Private Sub cmdFirst()
data_navigator.Recordset.MoveFirst End Sub Private Sub cmdFirst_Click() data_navigator.Recordset.MoveNext End Sub Private Sub cmdPrevious_Click() data_navigator.Recordset.MovePrevious End Sub Private Sub cmdLast_Click() data_navigator.Recordset.MoveLast End Sub

Run the application and you shall obtain the interface as shown in Figure 24.1 below and you will be able to browse the database using the four navigation buttons.

Figure 24.1




Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy