Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    jonesy29847 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Detroit area
    Posts
    43

    Record navigation buttons work backward

    I think I hosed my self here, I added an Autonumber field to a table with 277 records in it, I then made the field a key field.

    I have record navigation buttons with the following code:
    Code:
    Private Sub Gotonext_Click()
        With Recordset
            If .AbsolutePosition = .RecordCount - 1 Then
            DoCmd.GoToRecord , , acFirst
        Else
            DoCmd.GoToRecord , , acNext
        End If
    End With
    End Sub
    
    Private Sub GotoPrev_Click()
        With Recordset
            If .AbsolutePosition = 0 Then
            DoCmd.GoToRecord , , acLast
        Else
            DoCmd.GoToRecord , , acPrevious
        End If
    End With
    
    End Sub
    When I use the Next record button I go to the first, designed in for wraparound, but when I use the Prev button the next record is displayed and Next goes to prev.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Have you tried:
    If .AbsolutePosition = 1 Then

  3. #3
    jonesy29847 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Detroit area
    Posts
    43

    New code, same result

    I tried to add a key field, and this is the result. It would appear that when I pasted the table the records were pasted backwards. Can someone explain to me what happened.

    This code moves to the next record...
    Code:
    Private Sub Gotonext_Click()
        With Recordset
        DoCmd.GoToRecord , , acPrev
    End With
    End Sub
    ...and this code moves to the previous.
    Code:
    Private Sub GotoPrev_Click()
        With Recordset
        DoCmd.GoToRecord , , acNext
    End With
    End Sub
    I have hosed myself, and want to know what mistake I made, and how to fix it.

    Much thanks.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Why do you have the With Recordset in the code? You are not using it. If you were then your code would look like:
    Code:
    With Me.Recordset
       .MoveNext
    End With

  5. #5
    jonesy29847 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Detroit area
    Posts
    43
    No joy.

    I really think I have hosed the table somehow when I tried to add an Autonumber key field to the table.

    Thanks

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Adding an AutoNumber field to a table should not be a problem. Have you already done a Compact and Repair? Any chance you can post your db?

  7. #7
    jonesy29847 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Detroit area
    Posts
    43
    I tried compact and repair, no joy, file attached

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    I made some changes but it seemed to be working as expected from the jump.

  9. #9
    jonesy29847 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Detroit area
    Posts
    43
    Yes I see the changes, but the next button still moves to the previous record, and the previous button moves to the next record.

    When I originally coded the buttons next called DoCmd.GotoRecord,,acNext and vise versa. Then I got the bright idea of adding an Autonumber Key field, after that I was hosed.

  10. #10
    jonesy29847 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Detroit area
    Posts
    43
    Correction, they work correctly, but the underlying code is backward.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Are we talking about the MainForm?

  12. #12
    jonesy29847 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Detroit area
    Posts
    43
    Yes Main.

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    What underlying code do you feel is backwards?
    Code:
    Private Sub Gotonext_Click()
       With Me.Recordset
          If .AbsolutePosition < .RecordCount - 1 Then
             .MoveNext
          End If
       End With
    End Sub
    Private Sub GotoPrev_Click()
       With Me.Recordset
          If .AbsolutePosition <> 0 Then
             .MovePrevious
          End If
       End With
    End Sub

  14. #14
    jonesy29847 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Detroit area
    Posts
    43

    Unhappy

    Perhaps I was a little convoluted in my post. I should have stated
    When I use the Next record button I go the the Previous, and when I use the Previous record button I got to the Next
    There have been a few iterations with the code, but always the same result, the code that should navigate to the next record navigates to the previous, and vice versa. I initially designed to code to wraparound, to avoid the error message that comes up when you are at either end of the recordset and try to navigate beyond it.

    When I first switched record navigation to VB all was well, then I got the bright idea to add the autonumber field and make it the key.

    I exported the records to excel, blew the table data away, added the autonumber field and populated it, in excel. When I imported the spreadsheet I was hosed.

    Adding to all this confusion the Autonumber field looks correct, the lowest number is assigned to the first record, and the highest to the last.

    Whew!

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    You do know that you have an OrderBy Clause property of the form that sorts descending, right?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Navigation Buttons Stop My Code
    By millerdav99 in forum Programming
    Replies: 6
    Last Post: 03-18-2011, 11:13 AM
  2. Replies: 2
    Last Post: 01-27-2011, 08:04 AM
  3. Navigation buttons deafult saving
    By accesscoder in forum Forms
    Replies: 3
    Last Post: 10-16-2010, 03:24 PM
  4. Replies: 0
    Last Post: 12-12-2009, 04:45 PM
  5. Navigation Buttons not working please help
    By dinarocks74 in forum Access
    Replies: 3
    Last Post: 06-26-2009, 10:15 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