• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1300
  • Last Modified:

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
0
peakpeak
Asked:
peakpeak
  • 4
1 Solution
 
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:
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:
Why the "B" grade?  My answer gave you everything you needed to accomplish this...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now