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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.