Navigation Button Active (1 Viewer)

ilanray

Member
Local time
Today, 03:51
Joined
Jan 3, 2023
Messages
116
Hi
I have a form with 4 navigation button.
at navigationButton109 I have a button component , when I click on it I create an event that make visible the other navigation whcih works great
Code:
[forms]![TaskNavigation]![NavigationButton113].visible = true
the problem is I would like to make this navigation active so i tried to do
Code:
[Forms]![TaskNavigation]![NavigationButton113].SetFocus
But it doesn't work, I even tried to add
Code:
SendKeys "[Enter]"
but still it doesn't works

Can someone please help me?

thanks
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 19:51
Joined
Feb 28, 2001
Messages
27,189
Are you doing this from another form? I.e. trying to make FormA's nav button have focus while you are running from FormB's code?

If this is FormA's code talking about a button on FormA, then the [Forms]![...] syntax can be replaced with Me. and should simplify typing.

As to the "it doesn't work" comment... so what DOES it do? Anything? And WHERE in your code (what event context) does this failing code reside?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:51
Joined
Oct 29, 2018
Messages
21,474
When you click on a button, it fires the Click event. So, to "activate" a button using code, you can call its Click event code. For example:
Code:
Call NavigationButton113_Click()
 

Edgar_

Active member
Local time
Yesterday, 19:51
Joined
Jul 8, 2023
Messages
431
For choosing a form located in a navigation control, I like using:
DoCmd.BrowseTo acBrowseToForm, "FormName", "NavForm.NavSubFormControl"
Where:
FormName = The name of the form you want to open
NavForm = The name of the form holding your navigation control
NavSubFormControl = The name of the subform control that shows the Form that appears when you click a navigation button
 

ilanray

Member
Local time
Today, 03:51
Joined
Jan 3, 2023
Messages
116
Hi
let me try to explain better:
I have 1 form with 4 navigation bar. the button is in Nav A, when I click on it on make Nav B visible but the focus is still in Nav A. I would like the focus will be on Nab B
None if the option above that you guys mentioned is working. The focus is still on Nav A
 

Minty

AWF VIP
Local time
Today, 01:51
Joined
Jul 26, 2013
Messages
10,371
If you are on the form where these buttons are simply use

Me.NavigationButton113.Visible = True
Me.NavigationButton113.Setfocus

If not you would have to set focus to the form first, then set focus to the control.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 19:51
Joined
Feb 28, 2001
Messages
27,189
when I click on it on make Nav B visible but the focus is still in Nav A.

See Minty's suggestion, but I will point out that having focus and being visible are TWO SEPARATE PROPERTIES and thus it will take two VBA actions to achieve your goal. Setting something visible doesn't change focus. It changes visibility. Setting the focus doesn't change visibility (though it DOES interact with it). You MUST set visibility BEFORE you set focus because (as noted in the linked article) you cannot set focus to something that is not visible.

 

Tom Robinson

New member
Local time
Yesterday, 17:51
Joined
Jan 7, 2015
Messages
5
SetFocus to a button doesn't fire the button's Click event.
To do that you need call the button's event handler directly.
To do this from another form, you need to change

Code:
Private Sub NavigationButton113_Click()
     -to-
Public Sub NavigationButton113_Click()
and then you can do
Code:
[forms]![TaskNavigation].NavigationButton113_Click

The button does not need to have the Focus.
The button does not need to be Enabled.
The button does not need to be Visible.
 

ilanray

Member
Local time
Today, 03:51
Joined
Jan 3, 2023
Messages
116
Hi
Minty, your solution unfortunately is not working. when I am the the other tab and I click on NavigationButton113 I get an error message compile error method or data member not found
Tom, what do you mean by creating a public sub? currently I don't have anything on the click event. since it is navigationButton you don't use the click event . You have to use the navigation destination name which let me choose a form from a list
 

Edgar_

Active member
Local time
Yesterday, 19:51
Joined
Jul 8, 2023
Messages
431
Did you try post #4?
That's how I move through navigation forms programmatically.
 

ilanray

Member
Local time
Today, 03:51
Joined
Jan 3, 2023
Messages
116
Yes i tried all of them. The navigation works differently from a button so i guess that's why is doesn't work
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:51
Joined
Oct 29, 2018
Messages
21,474
Yes i tried all of them. The navigation works differently from a button so i guess that's why is doesn't work
Are you able to share a sample db, so we can see what's going on? Thanks.
 

Edgar_

Active member
Local time
Yesterday, 19:51
Joined
Jul 8, 2023
Messages
431
Yes i tried all of them. The navigation works differently from a button so i guess that's why is doesn't work
You sure this is not what you're looking for?
 

Attachments

  • navs2.accdb
    448 KB · Views: 63

Edgar_

Active member
Local time
Yesterday, 19:51
Joined
Jul 8, 2023
Messages
431
Glad it worked for you.

Navigation controls are often misunderstood, as you can see. The other posters may have thought you were talking about regular buttons that you set up for navigation, but a Navigation control has its own behavior.

If you analyze it, the Navigation control that you can drag into the UI from the Ribbon is a Navigation control (a button manager) plus a Subform control. You can remove its "design" and it will let you move the two pieces independently.

The buttons within a Navigation control are called NavigationButton objects. The Navigation control is a component that handles creating buttons and connecting them to the Subform control. Buttons inside a Navigation control have things in common with regular buttons, but they also have extra features like NavigationTargetName and NavigationWhereClause. These extra features are not found in regular buttons.

If you look at the Subform control that comes with the Navigation control, you'll find that even though it has Master and Child links when you check, these properties are set to false by default. Also, these properties don't show up in the UI properties, so you can't set them. The subform control has its own way of working, so you can't handle it exactly like you would regular buttons and subform controls.

Because Navigation Buttons within the Navigation Control have their own built-in Click event, adjusting it as others suggested was not possible. If you added a Click event to a Navigation Button, the code would simply run in addition to what it already does by default.

This and much more can be found if you inspect your form with the debugger.
 

Users who are viewing this thread

Top Bottom