Results 1 to 6 of 6
  1. #1
    Join Date
    May 2008
    Posts
    48

    Unanswered: Move cursor to the last record

    Hi all,

    I am trying to execute following code so that whenever user open the form, it display the contents of last record.

    Private Sub Form_Open(Cancel As Integer)
    Dim dbs As Database
    Dim rcd As Recordset
    Set dbs = CurrentDb
    Set rcd = dbs.OpenRecordset("Customer")
    Me.Text0.Locked = True
    Me.Text1.Locked = True
    If rcd.RecordCount = 0 Then
    Me.CmdAdd.Enabled = True
    Me.CmdAdd.SetFocus
    Me.CmdSave.Enabled = False
    Me.CmdDel.Enabled = False
    Me.CmdSave.Enabled = False
    Me.CmdUndo.Enabled = False
    Else
    rcd.MoveLast
    Me.CmdAdd.Enabled = True
    Me.CmdAdd.SetFocus
    Me.CmdSave.Enabled = False
    Me.CmdDel.Enabled = True
    Me.CmdSave.Enabled = False
    Me.CmdUndo.Enabled = False
    End If
    End Sub

    But it is not performing properly. If there is no record, it works but when there are number of records, cursor does not go the last record.

    I solicit your valued suggestion

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try:
    Code:
    If rcd.EOF = True And rcd.BOF = True Then
        ' No record.
        . . .
    Else
        ' Recordset has records.
        rdc.Movelast
        . . .
    End If
    Have a nice day!

  3. #3
    Join Date
    May 2008
    Posts
    48
    With your coding, still cursor not going to last record.

    Kindly let me know where this code to be written whether on load or on open or somewhere else.

  4. #4
    Join Date
    May 2008
    Posts
    48
    rcd.movelast

    was not working. However,

    DoCmd.GoToRecord , , acLast

    is perfectly working

    Now problem solved. But, can you tell me what is the difference between these two?

  5. #5
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You place it just after the line that deletes the row:
    Code:
    Private Sub Command_Delete_Click()
    
        
        Me.Recordset.Delete
        If Me.NewRecord = True Then
            DoCmd.GoToRecord , , acLast
        End If
        
    End Sub
    Have a nice day!

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    In your original code you, making sure you had the Microsoft DAO 3.6 Object Library in your references, needed

    Dim rcd As DAO.Recordset

    The difference is that with the first you're opening a recordset clone, and with the later

    DoCmd.GoToRecord , , acLast

    you're moving within the original recordset you have already have open as the recordsource of your form.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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