Krish
Krish

Reputation: 5917

Programmatically select a NavigationControl Tab in Ms Access

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

Upvotes: 1

Views: 3058

Answers (2)

Daniel
Daniel

Reputation: 1

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

NavigationForm.TabC.SetFocus
SendKeys "{Enter}"

Upvotes: 0

Jörg Brenninkmeyer
Jörg Brenninkmeyer

Reputation: 3344

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.

Upvotes: 1

Related Questions