It is the method of Recordset object. The RecordsetObject.MoveFirst is used to move to the first record of Recordset object.
The example below uses the four moving methods of Recordset object including MoveFirst, MoveNext, MovePrevious, and MoveLast. For instance, you have the form as figure:
- When the form loaded, a record was retrieved from Recordset object to display on the form like the figure above.
- When you click the First command button, Recordset object will move to the first record.
-When you click the Previous command button, Recordset object will move back one record after the current record.
-When you click the Next command button, Recordset object will move to the next record of the current record.
-When you click the Last command button, Recordset object will move to the last record.
The VBA code that is applicable to the example is shown below:
Private Sub cmdFirst_Click()
Private Sub cmdNext_Click()
On Error GoTo aa ' Track error
If Not Rs.EOF Then ' If the record is not the last record
Rs.MoveNext ' then it will move to the next record
aa: Resume Next ' Though the error occurs, the program still continues
Private Sub cmdPrevious_Click()
On Error GoTo aa
If Not Rs.BOF Then
aa: Resume Next
Private Sub cmdLast_Click()
' When the form is closed, you need to close and clear Recordset and Database objects from the memory.
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: