Lesson 24: Creating database applications in VB-Part II

Custom Search

<Previous Lesson> <<Home>> < Next Lesson>

In Lesson 23, you have learned how to create a simple database application using data control. In this lesson, you will work on the same application but use some slightly more advance commands. The data control support some methods that are useful in manipulating the 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

data1.RecordSet.MoveFirst                      

 ' Move to the last record

data1.RecordSet.MoveLast                      

 ' Move to the next record

data1.RecordSet.MoveNext                     

' Move to the first record

data1.RecordSet.Previous 

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

data1.RecordSet.AddNew                          ' Adds a new record

data1.RecordSet.Update                           ' Updates and saves the new record

data1.RecordSet.Delete                            ' Deletes a current record

*note: data1 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 Command1_Click()
data1.Recordset.MoveFirst
End Sub


Private Sub Command2_Click()                     
data1.Recordset.MoveNext     
End Sub


Private Sub Command3_Click()
data1.Recordset.MovePrevious
End Sub

Private Sub Command4_Click()
data1.Recordset.MoveLast
End Sub

 

Run the application and you shall obtain the interface below and you will be able to browse the database using the four command buttons.


  Bookmark and Share

<Previous Lesson> <<Home>> < Next Lesson>

Copyright ® 2008 Dr.Liew Voon Kiong . All rights reserved |Contact: admin@vbtutor.net

[Privacy Policy]