Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Navigation Buttons, wonky 2

Status
Not open for further replies.

timhans

Programmer
Jun 24, 2009
75
Hello. I have been asked to put navigation buttons on a bound form, so users can find previous entries, have used wizard. under lying table has only one index field(Primary key auto number). Records go from 1-1551, goto first button go's to record 145 and can not move past that even with previous button. Last button gets me to last record 1551 but previous button jumps back 50 records to 1501, the next button moves back to last record again. I am befuddled as to this behavior
any insight is appreciated.
 
How are ya timhans . . .

You'd didn't provide any code so try the following:
Code:
[blue]Private Sub movFirst_Click()
   If Me.Recordset.RecordCount <> 0 Then
      If Me.CurrentRecord <> 1 Then Me.Recordset.MoveFirst
   End If
End Sub

Private Sub movLast_Click()
   If Me.Recordset.RecordCount <> 0 Then
      If Me.CurrentRecord < Me.Recordset.RecordCount Then
         Me.Recordset.MoveLast
      End If
   End If

End Sub

Private Sub movNext_Click()
   If Me.Recordset.RecordCount <> 0 Then
      If Me.CurrentRecord < Me.Recordset.RecordCount Then
         Me.Recordset.MoveNext
      End If
   End If

End Sub

Private Sub movPrev_Click()
   If Me.Recordset.RecordCount <> 0 Then
      If Me.CurrentRecord > 1 Then Me.Recordset.MovePrevious
   End If

End Sub[/blue]

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hey Aceman, thanks for responding. Your code is doing the same as the wizard code

Private Sub cmdprevious_Click()
On Error GoTo Err_cmdprevious_Click

DoCmd.GoToRecord , , acPrevious

Exit_cmdprevious_Click:
Exit Sub

Err_cmdprevious_Click:
MsgBox Err.Description
Resume Exit_cmdprevious_Click

End Sub

The other buttons are all similarly written, do you think it could be a table issue
 
Use a query with an ORDER BY clause as RecordSource instead of the table.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

[blue]timhans[/blue],

[blue]TheAceMan1[/blue]'s code doesn't do the same thing, even if it seems like it. He's got an extra portion in there verifying that you aren't trying to move through the recordset if it has no records - that could be a really important piece in some situations.

And if you go with [blue]PHV[/blue]'s suggestion, it'll take care of the order of your recordset - which is your problem here.

Try [blue]PHV[/blue]'s suggestion, and post back to let us know if that fixes the problem.


--

"If to err is human, then I must be some kind of human!" -Me
 
That did it, form use's query but did not have it sorted, is now sorted on autonumber, all works well. Am using Aceman's coding as this seems much better then wizard's coding and is new to me, so got to learn two new thing's today!. Thanks
Aceman, PHV and kvj1611
 
timhans . . .

If you take a good look at the code, you'll see that [blue]I check if movement is possible before I make the move.[/blue] I did this because I seem to remember that DoCmd would error if the movement was not possible.

Its a few extra lines of code but no [blue]error handling[/blue] is necessary!

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Aceman, the code you provided is clean, I like that no error handling is nessasary, good simple examples of if, then statements as well as using Recordset and Recordcount for me to look at as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top