Move to previous record

GBalcom

Much to learn!
Local time
Today, 14:33
Joined
Jun 7, 2012
Messages
462
I know this should be simple...but for some reason, the recordset clone is not showing BOF as true when I'm on the first record in the table......please see code below:

Code:
On Error GoTo Error_Handler
Dim rs As Recordset

Set rs = Me.RecordsetClone

If rs.BOF = True Then
MsgBox "You are at the first record."

Else

DoCmd.GoToRecord , , acPrevious
OpenPath




End If




Exit_Procedure:
    rs.Close
    Set rs = Nothing
    On Error Resume Next
    Exit Sub
    
Error_Handler:
    DisplayErr Err.Number, Err.Description, "frmMSDS", "cmdPreviousRecord_Click()"
    
    Resume Exit_Procedure
    Resume
End Sub

Thanks!
 
I know this should be simple...but for some reason, the recordset clone is not showing BOF as true when I'm on the first record in the table......please see code below:

Indeed, not even the real Me.Recordset show .BOF / .EOF show true when on the First / Last record of a Multiple Items form.

From my experience, it is necessary to perform the .MoveNext method first, then to test if .EOF is then True.

So perhaps moving backwards, it is necessary to call .MovePrevious method, then to test if .BOF is then True.
 
Oh, and I would suggest going all the way with the use of the daoRS object. Sample code to find a specific record...

Code:
  Dim daoRS As DAO.Recordset

  'Locate the record if we received a valid ID
  If lngRecordID > 0 Then
    Set daoRS = Me.RecordsetClone
    daoRS.FindFirst ("[id] = " & lngRecordID)
    'If we could find the newly added record, jump to it
    If Not daoRS.NoMatch Then
      Me.Bookmark = daoRS.Bookmark
    End If
  End If

  'Clean up the connection to the database
  Set daoRS = Nothing

Instead of making a call to DoCmd.GoToRecord , , acPrevious, use Me.RecordsetClone, attempt to move to the previous record, and if the .BOF is not true, then Me.Bookmark = daoRS.Bookmark.
 
My usual bitchy self would suggest to google for the answer. I did - and to my utter amazement what I found figuring so prominently on utter access, committed by Access EXPERTS, http://www.utteraccess.com/forum/BOF-EOF-VBA-t1388679.html

that might have inspired you is utterly and shockingly WRONG!

The correct text is here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms675787%28v=vs.85%29.aspx


EOF/BOF mark positions at the beginning/end of file before/after any records.

TO see if you are on record 1 use .AbsolutePosition property. To see if you are on last record of a recordset use the .RecordCount property together with .ABsolutePosition
 
spike is right.

eg eof is true AFTER you have moved off the last record.

hence

Code:
set rst=openrecordsetr("somequery")
while not rst.eof
   process record
   rst.movenext
wend

if no records, then eof is immediately true, and no records are processed
if 1 record then eof only becomes true after the first movenext
 

Users who are viewing this thread

Back
Top Bottom