cmdNext Error Msg not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SeadooRider
    New Member
    • Jan 2013
    • 48

    cmdNext Error Msg not working

    I have the following code for a next record button in an access form that won't bring up msgbox after last record is reached.

    Code:
    On Error goTo_cmdNext_click
    DoCmd.GoToRecord, , acNext
    Exit_cmdNext_click
    Exit Sub
    Err_cmdNext_click
    Msgbox "No more records etc.", , "Last record"
    Resume Exit_cmdNext_click
    End Sub
    Please assist,
    Jason
    Last edited by TheSmileyCoder; Apr 11 '13, 12:58 PM.
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    The error is in the second line of your code. It needs to be
    Code:
    On Error GoTo Err_cmdNext_Click
    You are also missing a few colons. Try the following code
    Code:
    On Error GoTo Err_cmdNext_click
    
    DoCmd.GoToRecord, , acNext
    
    Exit_cmdNext_click:
    	Exit Sub
    	
    Err_cmdNext_click:
    	Msgbox "No more records etc.", , "Last record"
    	Resume Exit_cmdNext_click
    End Sub

    Comment

    • SeadooRider
      New Member
      • Jan 2013
      • 48

      #3
      The only difference I see is the capital C in click. that was a typo, the actual code does have a capital C but it still doesn't work.
      If I'm missing something completely here please dummy it down for me.

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        Line numbers are referencing my code.
        Line 1: You have goTo_cmdNext_cl ick. You can't have the GoTo connected to the line you want to go to. Also, the name of the line is actually Err_cmdNext_cli ck. So I put GoTo Err_cmdNext_cli ck.

        Lines 5 and 8. You have to have colons at the end of the name. Otherwise, Access thinks that it is either a variable or a procedure that you are trying to call.

        I'm guessing (almost sure) that you don't have option explicit set. See Require Variable Declaration on why you need it and how to make it set automatically.

        Comment

        Working...