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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create your own Navigation without error messages

Form Basics

How to create your own Navigation without error messages

by  adamroof  Posted    (Edited  )
Just want to share this code for making your own navigation buttons that (1) dont go to a new record when you get to the end (2) doesnt give you error 'You cant go to the specified record' (3) Automatically recounts your form records on Form Filters and Queries. Obviously change the names where needed and you can still add your own Go To Last and Go To First buttons for full nav effect.

*** Create two textboxes, Text30 and Text33, create a label and make it say "Of" and place it between text30 and text33 on your form. I bolded text30 and text 33 ***

In Form Design, change Text30 Control Source to (=[Form].CurrentRecord)
Text33 is unbound, controlled by the On Current Event


*** Create On Current Event ***

Private Sub Form_Current()

If Me.RecordsetClone.RecordCount > 0 Then
Me.RecordsetClone.MoveLast
Me![Text33] = Me.RecordsetClone.RecordCount
Else
Exit Sub
End If

End Sub

*** Create a button to go forward ***
*** Replace VBA Code Generated with below, changing names as needed ***

Private Sub ClientNextBtn_Click()
On Error GoTo Err_ClientNextBtn_Click

If Text30 = Text33 Then
Exit Sub
Else
DoCmd.GoToRecord , , acNext
End If

Exit_ClientNextBtn_Click:
Exit Sub

Err_ClientNextBtn_Click:
Resume Exit_ClientNextBtn_Click
End Sub

******
For the Previous button,
******

Private Sub ClientPrevBtn_Click()
On Error GoTo Err_ClientPrevBtn_Click

DoCmd.GoToRecord , , acPrevious

Exit_ClientPrevBtn_Click:
Exit Sub

Err_ClientPrevBtn_Click:
Resume Exit_ClientPrevBtn_Click
End Sub

******

The key to this is to include the error handler, but omit the MsgBox Err.Description that Access Auto Generates.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top