Run code on Next Record button

I need to hook the Next and Previous buttons on the bottom of my form window to run VB code. Probably very easy but I cannot find any samples.

Regards
Peter
LVL 28
peakpeakAsked:
Who is Participating?
 
mbizupCommented:
Btw, the command button wizard makes it very easy to createcustom navigation buttons.  Select the type of button you want (next, prev, etc) from the Record Navigation category, and the code for the button will be atomaticlly generated.  All that's left is for you to modify the button's click event with your code:

Private Sub cmdNextRecord_Click()
On Error GoTo Err_cmdNextRecord_Click

    '*** Add any code that needs to run before a record change
    '*** Here.

    DoCmd.GoToRecord , , acNext
Exit_cmdNextRecord_Click:
    Exit Sub
Err_cmdNextRecord_Click:
    MsgBox Err.Description
    Resume Exit_cmdNextRecord_Click  
End Sub
0
 
mbizupCommented:
There are no events for the navigation buttions that you can add code to.  The form's current event will fire with each record change, and may work for you.  If that is not an option, you would have to create custom navigation buttons, set the form's Record Navigation Buttons property to "No" (and maybe consider disabling the mouse wheel for record changes).
0
 
mbizupCommented:
>If that is not an option...
A reason that the Current event might not be an option is that if fires AFTER the record has changed.  
0
 
mbizupCommented:
Why the "B" grade?  My answer gave you everything you needed to accomplish this...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.