Results 1 to 2 of 2

Thread: bof and eof

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    Singapore
    Posts
    98
    Hi guys!

    How exactly does rst.bof or rst.eof works when dealing with recordsets?
    Does it refer to the first/last record in a recordset or what?

    how do i find out the position of the current record in a recordset?

    Help!


  2. #2
    Addicted Member
    Join Date
    Sep 2000
    Posts
    138
    .bof and .eof are two properties of a recordset referring to, respectively, the beginning and end of the recordset, which is the memory mapping of a hard table or TableDef. They are not the first or last record, but, respectively again, the previous position to the first record and next positions to the last record. These two properties are very useful as is shown in the following code:

    Code:
    ---------------------------------
    With rst
    .MoveFirst
    Do
    .MoveNext
    Loop Until .Eof
    End With
    ---------------------------------

    The above code guides the pointer of the recordset to scroll through all the records in the rst while, with the clause Until .Eof, it stops coming across the End of File. Without this clause the loop works on and produces an error.

    When an empty recordset is opened or created, both the .bof and .eof are true.

    With a recordset the current record is often unknown, especially when you have just used the .Update method. To get or retrieve the current record, you can use the .BookMark property of a recordset, e.g.:

    Code:
    ------------------------------
    With rst
    .MoveLast
    strBookMark = .BookMark
    .AddNew
    .
    .
    .
    .UpDate
    .BookMark = strBookMark ¡®Retrieving the current record, i.e. the original "Last" record.
    End With
    -----------------------------

    If you want to keep the absolute position of each record, you can use an array as bookmarks, e.g.:

    Code:
    -----------------------------
    Dim strBookMark() As String 'Or Variant
    Dim i As Long

    With rst
    ReDim strBookMark(.RecordCount-1)
    .MoveFirst
    While Not .Eof
    strBookMark(i) = .BookMark
    i = i + 1
    .MoveNext
    Wend
    End With
    -----------------------------

    Those are some of the features of the .bof and .eof properties.

    Hope it helps.

    ----------------------------
    Visual Basic Professional 6.0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width