Results 1 to 5 of 5
  1. #1
    jaarons is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    22

    Navigation Record Buttons in Forms

    Hi,



    Quick question. (Well, quicker than my last few)
    I have a form that scrolls through records. It has a previous records and a next records button.
    When its on the first record and you accidentally go previous record, it comes up with an error message (saying you can't go to the specified record), then a break in the macro. Same with, obviously, if you're in the last record and user chooses next.

    Is there a way for the button to be inactive if its the first record and user presses previous? Is there a way of there simply being an error message, and that's it, rather than the user seeing a macro dialogue box?

    Just wondering. Thanks.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I don't use macros... this is the VBA I use:
    Code:
    'Previous record
    Private Sub GoPrevious_Click()
       On Error GoTo Err_GoPrevious_Click
    
       DoCmd.GoToRecord , , acPrevious
    
    Exit_GoPrevious_Click:
       Exit Sub
    
    Err_GoPrevious_Click:
       If Err.Number <> 2105 Then
          MsgBox Err.Description & "   Error# " & Err.Number
       End If
    
       Resume Exit_GoPrevious_Click
    
    End Sub
    
    'Next record
    Private Sub GoNext_Click()
       On Error GoTo Err_GoNext_Click
    
       DoCmd.GoToRecord , , acNext
    
    Exit_GoNext_Click:
       Exit Sub
    
    Err_GoNext_Click:
       If Err.Number <> 2105 Then
          MsgBox Err.Description & "   Error# " & Err.Number
       End If
       
       Resume Exit_GoNext_Click
    
    End Sub

  3. #3
    jaarons is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    22
    Thanks. Excuse my ignorance with VBA code, but where do I put it?
    I first of all deleted the On Click macros I had with the two buttons "Previous Record" and "Next Record"
    I then went to On Click with one of the buttons and chose Code Builder. I pasted in the code, but it didn't work. Do I need to name the buttons GoPrevious and GoNext for it to work? Because that didn't seem to work either.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Yes, if you use the code as is, the button names would have to be "GoPrevious" and "GoNext".

    Open the form in design mode.
    Open the properties dialog box for the button "GoPrevious".
    Click on the EVENTS tab.
    Find the "On Click" row. Click in it. A dropdown arrow should appear.
    Click on the dropdown arrow.
    Select "Event Procedure"
    Click on the three periods (aka ellipsis)
    That should bring you to the IDE.
    For the code "GoPrevious", copy and paste everything from my example except the first line and the last line (ie "Private Sub GoPrevious_Click()" and "End Sub")

    Do the same for "GoNext".

    Save the form.
    Change to "Form View". Try the buttons.

  5. #5
    jaarons is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    22
    Great! That worked! Thanks again!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 06-01-2011, 06:44 PM
  2. Record navigation buttons work backward
    By jonesy29847 in forum Access
    Replies: 22
    Last Post: 04-11-2011, 06:17 AM
  3. Navigation Buttons Stop My Code
    By millerdav99 in forum Programming
    Replies: 6
    Last Post: 03-18-2011, 11:13 AM
  4. Navigation buttons deafult saving
    By accesscoder in forum Forms
    Replies: 3
    Last Post: 10-16-2010, 03:24 PM
  5. Navigation Buttons not working please help
    By dinarocks74 in forum Access
    Replies: 3
    Last Post: 06-26-2009, 10:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums