Results 1 to 6 of 6
  1. #1
    G3K0 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2017
    Posts
    6

    Using a command button for previous and next record. Get "You can't go to the specified record."

    So I think there is a simple answer here, but I am not sure why it happens. In a form, I have a command button for moving through records. Attached to this button is basic VBA code.

    Private Sub btnPreviousRecord_Click()


    DoCmd.GoToRecord , , acPrevious
    End Sub

    Easy Enough. When I click the previous button once, I go to the previous record, when I click it again, I get the error "You can't go to the specified record." I click End on the popup, and I click the previous record button again and go to the previous record.

    I can sift through all of my records, but every other click on either the previous or next button, I get a popup saying I can't go to the next record, even though it exists. The only true time that a record does not exist is when I press previous on the very first record, or next on the very last record.

    Suggestions?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    if you are at the 1st record you cant go to previous.
    theres no need for these buttons, access provides them at the form footer.
    NAVIGATION BUTTONS = TRUE

  3. #3
    G3K0 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2017
    Posts
    6
    Ranman256,

    Thanks for the info, yes I am aware I cannot go to the previous when I am at the very first and the next when I am at the very last. Adding these buttons is TECHNICALLY not necessary, I am also aware of the navigation buttons at the bottom, but for someone new coming across the form, it is more intuitive to have the obvious arrow buttons in my opinion. I do have code that grays out the previous arrow on the first record and grays out the next arrow on the last record.

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    There seems to be a lot out there on this subject. One suggested that the form loses focus when moving to another record and said to add the line Me.Setfocus. There are also mentions regarding the events that are fired, such as the BeforeUpdate and AfterUpdate among others.

  5. #5
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Maybe add error handling code in that button and trap that error, if it says "Cannot go to Previous Record" or whatever, just point it back to that button me.button.setfocus instead of displaying a pop up.

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    You might be doing something in the Form_Current event that's causing this. Try commenting out the event and see what happens.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 01-12-2016, 02:49 PM
  2. Replies: 11
    Last Post: 02-22-2015, 01:25 PM
  3. Replies: 30
    Last Post: 09-27-2013, 01:34 PM
  4. Replies: 10
    Last Post: 03-15-2013, 05:46 AM
  5. Replies: 8
    Last Post: 07-18-2012, 11:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums