Results 1 to 13 of 13
  1. #1
    redekopp is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108

    Change to different Navigation Button with VBA code

    Hello! My situation is that my form "Switchboard" has a Navigation Control. One of the navigation buttons is called "Dashboard" and is linked to a form called "navDashboard". Inside "navDashboard" I have a button that on click should run VBA code that changes the original Navigation Control from "Dashboard" to the other navigation button called "Agreements" which is linked to a form called "navAgreements". I don't want it to just update "Dashboard" with "navAgreements".

    How can I make this happen?

    Thank you!

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,976
    If you mean you want to change the focus to the Agreements button then add this line to the button click event code:
    Code:
    Me.Agreements.SetFocus
    NOTE that if you are using a built-in Access navigation form, these do not behave quite like other forms so the above MAY not work
    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

  3. #3
    redekopp is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    Quote Originally Posted by ridders52 View Post
    If you mean you want to change the focus to the Agreements button then add this line to the button click event code:
    Code:
    Me.Agreements.SetFocus
    NOTE that if you are using a built-in Access navigation form, these do not behave quite like other forms so the above MAY not work

    That does not work no, all it does is highlights the nav button. I need it to actually change to the nav button and its linked form.

    Thank you though.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,976
    As I don't use navigation forms, I'll now drop out & let someone else advise
    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

  5. #5
    Robyn_P's Avatar
    Robyn_P is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Nov 2017
    Posts
    150
    I'm not sure I've got this right, but are you saying you have two different control buttons that open different forms and you want to change which one is used? Could you just put the two buttons on top of each other in design mode and then with code change which is visible. Me.Agreements.Visible = True etc? Does that make sense?

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    I think you need to explain your requirement a little better, at this point we're just guessing at what you want.

    I'm thinking you have one button and you want to change the buttons caption as well as what happens when you click that button.

    I'm with Ridders as I don't use navigation forms either. They are a lot of bother and its much easier to roll your own.

  7. #7
    redekopp is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    Quote Originally Posted by moke123 View Post
    I think you need to explain your requirement a little better, at this point we're just guessing at what you want.

    I'm thinking you have one button and you want to change the buttons caption as well as what happens when you click that button.

    I'm with Ridders as I don't use navigation forms either. They are a lot of bother and its much easier to roll your own.
    Hi, I have attached an image of the database. On the Dashboard nav, it is the form "navDashboard". Inside of there is a subform in the "Active Wells" header. If I click the number 5, I want it so that it "clicks" my "Agreements" button on my main navigation and switches to that form instead, which is called "navAgreements". I know I can easily change what the "Dashboard" nav button shows, but I want it to actually click Agreements and move to that form.

    Does that help clear it up at all?

    Thanks!

    Click image for larger version. 

Name:	DB.PNG 
Views:	37 
Size:	35.0 KB 
ID:	35017

  8. #8
    redekopp is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    Hi guys, just bumping this back to the top one more time since the addition of the image, if it gets no responses tomorrow I will delete it. Thank you for your time!

  9. #9
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    First let me say I have never used a Navigation Control, but I have tried to understand what is going on a couple of times.

    I find it so much easier to "roll your own" nav form/control than to use the built in nav form.

    OK, I finally found a dB that had a nav control (because I couldn't build one and didn't want to take the time to try and learn how).

    So I added a normal (?) button to the form and added code to the button click event. Something like
    Code:
    Private Sub Command14_Click()
         Call NavigationButton11_Click      '(or whatever the button name is)
    End Sub
    This opened another form. Alright!!
    Oops .... but the nav buttons did not change to the correct colors (selected, un-selected) as if you clicked the nav button.
    It turns out that "clicking" a nav button is a mouse thing; Access handles all of the color changes.

    You can write code to make the nav buttons change color, I'm just not sure how the code will affect the mouse click nav button color changes; you might have to have code in the "LostFocus" event of the nav buttons to reset the default colors.

  10. #10
    redekopp is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    Quote Originally Posted by ssanfu View Post
    First let me say I have never used a Navigation Control, but I have tried to understand what is going on a couple of times.

    I find it so much easier to "roll your own" nav form/control than to use the built in nav form.

    OK, I finally found a dB that had a nav control (because I couldn't build one and didn't want to take the time to try and learn how).

    So I added a normal (?) button to the form and added code to the button click event. Something like
    Code:
    Private Sub Command14_Click()
         Call NavigationButton11_Click      '(or whatever the button name is)
    End Sub
    This opened another form. Alright!!
    Oops .... but the nav buttons did not change to the correct colors (selected, un-selected) as if you clicked the nav button.
    It turns out that "clicking" a nav button is a mouse thing; Access handles all of the color changes.

    You can write code to make the nav buttons change color, I'm just not sure how the code will affect the mouse click nav button color changes; you might have to have code in the "LostFocus" event of the nav buttons to reset the default colors.
    Thank you for the feedback Steve, i tried doing this with
    Code:
    Call Forms.Switchboard.Agreements_Click
    I received a Run-time error '2465': Application-defined or object-defined error


    Any advice?

    Thanks!

  11. #11
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    First, I would try
    Code:
    Call Forms!Switchboard.Agreements_Click
    Note the bang ("!" ) instead of the dot.

    What is the name of the main form?
    Is the "5" in a sub form? Might be a reference thing: See Refer to Form and Subform properties and controls


    Would have to see the dB to be for sure.....

  12. #12
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Might be a reference thing
    That's the exact reason I dislike Navigation Forms.
    It always seems to be a chore to get the right references.

  13. #13
    ba_joyner is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    1
    Try
    Code:
    Me.Parent!Dashboard.Caption ="Agreements"
    Me.Parent!Dashboad.NavigationTargetName = "navAgreements"
    The navigation button will still be called "Dashboard" but it will SAY "Agreements" and open the navAgreements form when you click it

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

Similar Threads

  1. Code for button to show Navigation Pane
    By MTSPEER in forum Programming
    Replies: 6
    Last Post: 07-27-2016, 10:39 AM
  2. Navigation Button
    By Kylie in forum Programming
    Replies: 3
    Last Post: 02-15-2015, 09:00 PM
  3. Replies: 3
    Last Post: 10-20-2014, 03:25 PM
  4. Navigation form property change
    By bdenton in forum Forms
    Replies: 2
    Last Post: 08-11-2011, 05:23 PM
  5. Replies: 3
    Last Post: 10-18-2009, 09:17 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