1

Currently we use this command to switch to a tab in a NavigationControl

DoCmd.BrowseTo acBrowseToForm, TabToOpen, Me.name & ".NavigationSubform"

This works fine if there is a unique NavigationTargetName for the selected Tab/Button. If we have two or more Tabs with the same target form name, we are unable to open a specific Tab. -The first tab with the matching targetName is opened-.

I.e. TabA and TabC has the same targetFormName X if we use the following command

DoCmd.BrowseTo acBrowseToForm, X, Me.name & ".NavigationSubform"

TabA is activated.

Problem: How do we activate TabC?

we've tried to do NavigationForm.TabC.SetFocus & NavigationForm.navBarTop.Tabs(9).SetFocus with no luck.

The.SelectedTab property is read only.

Regarding why we have same targetFormName: We use one form but dynamic SQL depends on the selected tab to reduce having x number of same forms for different state of data.

Many thanks

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Krish
  • 5,917
  • 2
  • 14
  • 35
  • Suggest instead of Navigation form, you use a normal subform with some buttons on main form to manage filtering the subform. – June7 Mar 21 '19 at 20:03
  • Everything I see says have to reference form associated with the tab and since you use same form for each NavigationTarget, likely no practical way to do this with Navigation form. – June7 Mar 21 '19 at 22:09
  • @Gustav not sure what you think you are achieving with your rollbacks here. Any further such actions will only lead to post locking. – Martijn Pieters Jul 03 '20 at 21:15
  • @MartijnPieters: It was wrongly retagged `[vba]` from the correct `[access-vba]` as this question bears no relevance outside a _Microsoft Access_ environment. You (and user _braX_) have done so for many questions, new, old, even very old, thereby destroying both the history (_recent activity_) as well as the search options. I believe you expect some positive effect of this massive retagging but, trust me, the effects are negative, not even neutral. Thus, I kindly encourage you to please refrain from this in the future. – Gustav Jul 04 '20 at 15:04
  • @MartijnPieters: Oh, I've just noticed the comment from @Erik A [here](https://stackoverflow.com/questions/55210315/) that your reasoning could be that `[access-vba]` should be deprecated like `[excel-vba]` is. But that is not the case. – Gustav Jul 04 '20 at 15:25

2 Answers2

1

I found a workaround after facing the same problem.

Use the TabIndex property to temporarily move the navigation button that you want to open to the beginning, i.e. TabIndex = 0. Then trigger the BrowseTo command, and afterwards set the TabIndex back to the original value. For me this works and there's no negative visual effect or similar.

Given your example with TabC, this would result in something like this:

NavigationForm.TabC.TabIndex = 0
DoCmd.BrowseTo acBrowseToForm, X, Me.name & ".NavigationSubform"
NavigationForm.TabC.TabIndex = 2

Of course, this can be made more dynamic e.g. by having a mapping from tab name to index position and then using the same code for all tabs in combination with that mapping.

Jörg Brenninkmeyer
  • 3,304
  • 2
  • 35
  • 50
0

I found this workaround: select the tab you want using SetFocus and then simulate pressing the Enter key.

NavigationForm.TabC.SetFocus
SendKeys "{Enter}"

Daniel
  • 1
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 30 '22 at 10:09