Results 1 to 12 of 12
  1. #1
    Join Date
    Sep 2023
    Posts
    4

    Reproducing the Navigation Bar using Command Buttons

    Hi all! and THANK YOU for your help!

    Can someone please assist in making these codes to work? The command buttons are located in the Form footer section. When I run any one of the buttons, I get this:
    "Compile error: Method or data member not found."
    showing the error to be in the Private Sub Form_Current() section at all the
    "[...]enabled" lines.
    (PS: after this works, I would like to add the "page of page" section of the Navigation Bar.)



    Code:
    Private Sub CmdFirst_Click()On Error Resume Next
    DoCmd.GoToRecord , , acFirst
    End Sub
    
    Private Sub CmdNext_Click()
    On Error Resume Next
    DoCmd.GoToRecord , , acNext
    End Sub
    
    Private Sub CmdLast_Click()
    On Error Resume Next
    DoCmd.GoToRecord , , acLast
    End Sub
    
    Private Sub CmdNew_Click()
    On Error Resume Next
    DoCmd.GoToRecord , , acNew
    End Sub
    
    Private Sub CmdBack_Click()
    On Error Resume Next
    DoCmd.GoToRecord , , acPrevious
    End Sub
    
    
    Private Sub Form_Current()
    On Error Resume Next
    If Me.CurrentRecord = 1 Then
         Me.CmdBack.Enabled = False
         Me.CmdFirst.Enabled = False
    Else
           Me.CmdBack.Enabled = True
           Me.CmdFirst.Enabled = True
    End If
    
    If Me.CurrentRecord = Me.Recordset.RecordCount Then
            Me.cmdLast.Enabled = False
    Else
            Me.cmdLast.Enabled = True
    End If
    
    If Me.CurrentRecord >= Me.Recordset.RecordCount Then
            Me.CmdNext.Enabled = False
    Else
            Me.CmdNext.Enabled = True
    End If
    
    
    If Me.NewRecord Then
            Me.CmdNew.Enabled = False
    Else
            Me.CmdNew.Enabled = True
    End If
    End Sub



    Last edited by ValerydeMassia; 09-27-2023 at 03:07 PM.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    why would you make more work programming buttons that are built-in to every form?

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Those are really command buttons? The error implies they are a control that doesn't have that property. Can you attach the db here, or a representative sample?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Here's a navigation bar custom class. Just 3 lines of code in your form.

    There are several optional configurations such as cycling records, message boxes, optional buttons, Record n of n label, etc.

    Edit: works in the form footer, as well as in subforms (with buttons on either the main form or the subform.)
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    A custom NavBar class is a great example of code portability. Write it once and use it anywhere with just a few lines of code.

    Code:
    Dim clsNB as clsFormNavBar   'in the declarations section
    
    Private Sub Form_Load()
    
    
        Set clsNB = New clsFormNavBar
        clsNB.InitCls Me, Me.cmdPrev, Me.cmdNext, Me.cmdFirst, Me.cmdLast, Me.cmdNew, Me.LblCount, Disable
    
    
    End Sub
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #7
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Quote Originally Posted by ranman256 View Post
    why would you make more work programming buttons that are built-in to every form?
    Frequently, because you can't disable the free text search function that comes with them.
    Try running that on a big dataset with an Azure SQL hosted backend and you'll see why you don't want it there.

    Disabling adding a new record without setting the form to allow additions = No would be helpful as well, though isn't quite such a deal breaker.
    If those were available options I'd use them a lot more.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Another reason for 'rolling your own' nav buttons is that the built in controls are fairly small and difficult for some people to use. Also tricky to use when running Access on a touch screen tablet.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  9. #9
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Frequently, because you can't disable the free text search function that comes with them.
    Never even noticed the text search before. The first thing I usually do is set record selector and Navigation bar to No.
    I rarely use them or the custom Nav Bar for that matter. About the only time I turn on the navigation bar is during development to see if the correct number of records are being returned.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  10. #10
    Join Date
    Sep 2023
    Posts
    4
    very sorry for the crossing... won't happen again unless I mention why. Thank you for flagging it.

  11. #11
    Join Date
    Sep 2023
    Posts
    4
    Isladog, that is a very big part of the reason I want this navigation bar. Thank you for expressing it better than I could ever have.
    Last edited by ValerydeMassia; 09-28-2023 at 04:27 PM. Reason: not sure I wrote this as reply to IslaDog

  12. #12
    Join Date
    Sep 2023
    Posts
    4
    Quote Originally Posted by moke123 View Post
    Here's a navigation bar custom class. Just 3 lines of code in your form.

    There are several optional configurations such as cycling records, message boxes, optional buttons, Record n of n label, etc.

    Edit: works in the form footer, as well as in subforms (with buttons on either the main form or the subform.)

    Thank You ! Wow! Nice!

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

Similar Threads

  1. Replies: 4
    Last Post: 01-20-2017, 08:16 AM
  2. Replies: 2
    Last Post: 04-01-2016, 11:13 AM
  3. navigation for records with buttons
    By waqas in forum Programming
    Replies: 2
    Last Post: 02-23-2013, 06:48 AM
  4. Replies: 1
    Last Post: 10-08-2012, 01:15 AM
  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