We help IT Professionals succeed at work.

Run code on Next Record button

peakpeak
peakpeak asked
on
Medium Priority
1,338 Views
Last Modified: 2008-01-09
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
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
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).
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
>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.  
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
Why the "B" grade?  My answer gave you everything you needed to accomplish this...
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.