Microsoft Access 2007 tutorial:DAO recordset properties


DAO recordset properties

IV.1.6.RecordsetObject.BOF

It is the property of Recordset object. The RecordsetObject.BOF is used to check the following conditions:

- If the Recordset object does not contain the record, the RecordsetObject.BOF is set to True.

- If the position of the current record is on the left of the first record, the RecordsetObject.BOF is set True too.

IV.1.7.RecordsetObject.EOF

This property is used to check the following conditions:

- If Recordset object does not contain the record, the RecordsetObject.EOF property will take True.

- If the location of the current record beyond the position of the last record, the RecordsetObject.EOF property will take True also.

IV.1.8. RecordsetObject.RecordCount

TheRecordsetObject.RecordCount property is used count the number of records in the Recordset object.

IV.1.9.RecordsetObject.AbsolutePosition

This property is use for the following terms:

- Display the position of the current record in the Recordset object.

- Define the location of the current record in the Recordset object.

This example will demonstrate the using of the Recordset object's properties including BOF, EOF and AbsolutePosition. For example, you have the DisplayData form as figure:

Access 2007 Recordset Object Propertis 

- When you click the Read Data command button, the first record was displayed in the CategoryID and CategoryName text boxes. In addition, the message box dialog will display this first record with its position. Then it will display the next record until the last record with each its position. While each record displays on the message box, it also displays in the two text boxes. Look at the figure below:

Access 2007 display record and its position 

 

The VBA code below fulfills the conditions above:

Option Compare Database
      Dim Db As DAO.Database
      Dim Rs As DAO.Recordset

Private Sub Form_Load()

      Set Db = CurrentDb
      Set Rs = Db.OpenRecordset("TblCategory", dbOpenDynaset)

End Sub



Private Sub CmdReadData_Click()

      If Rs.BOF = True Then
      MsgBox "The table does not have a record"
      Else
          While Not Rs.EOF
          txtCateID.Value = Rs(0)
          txtCateName.Value = Rs(1)

          MsgBox Rs(0) & " " & Rs(1) & vbCrLf & "The position of the   Record is:" & " " & Rs.AbsolutePosition + 1
          Rs.MoveNext

           Wend

      End If

End Sub




Comments

CAPTCHA image



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.