Activating a tab in a navigation subform (1 Viewer)

liddlem

Registered User.
Local time
Today, 00:17
Joined
May 16, 2003
Messages
339
I am busy creating a bespoke markbook for a school.

I have a form (Called Frm_SubjectSetup)
On Frm_SubjectSetup is a navigation subform (Default name of NavigationSubform)
Each of the tabs is named 'Term 1', 'Term 2', 'Term 3' and 'Term 4' respectively
And naturally, each tab has its own subform containing data that relates to the term.

On Frm_SubjectSetup, I have a combobox where the row source is

Code:
SELECT Q_Res_Hdr.ID, [Subject] & [Yr_Level] AS Subj, Q_Res_Hdr.Subject, Q_Res_Hdr.Yr_Level, Q_Res_Hdr.Term
FROM Q_Res_Hdr
ORDER BY Q_Res_Hdr.Subject, Q_Res_Hdr.Yr_Level, Q_Res_Hdr.Term;

My aim is to have the correct tab activated, based on the selection that the user makes in the combobox.
(Clicking on each tab is showing me the correct information)

In the ComboBox.AfterUpdate event, I have tried the following.

Code:
Dim myTerm as String
myTerm = "Term " & CStr(ActiveControl.Column(4))

DoCmd.BrowseTo ObjectType:=acBrowseToForm, _
   ObjectName:=myTerm, _
   PathToSubformControl:="Frm_SubjectSetup.navigationsubform"
   With Forms.Item("Frm_SubjectSetup").NavigationSubform
      .SetFocus
      !AssesmentDescr.SetFocus
   End With

'Control.Frm_SubjectSetup.NavigationSubform!myForm.SetFocus  //Throws an error - I know why.

    DoCmd.BrowseTo ObjectType:=acBrowseToForm, _
    ObjectName:=myTerm, _
    PathToSubformControl:="Frm_SubjectSetup.navigationsubform", _
    WhereCondition:="", _
    Page:="", _
    DataMode:=acFormEdit

// Just to make sure that it has nothing to do with the myTerm var, I hard coded it follows.
DoCmd.BrowseTo acBrowseToForm, "Term 3", "Frm_SubjectSetup.NavigationSubform"

None of the above seem to change the focus to the relevant tab.

Any help appreciated.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:17
Joined
May 7, 2009
Messages
19,169
you can try this code:
Code:
Dim ctl As Control
Dim myTerm As String
myTerm = "Term " & CStr(ActiveControl.Column(4))
For Each ctl In Me.Controls
    If TypeOf ctl Is NavigationButton Then
        If ctl.Caption = myTerm Then
            ctl.SetFocus
            SendKeys "{ENTER}"
            Exit For
        End If
    End If
Next

edit: you can use the above code Alone, without using BrowseTo
 

liddlem

Registered User.
Local time
Today, 00:17
Joined
May 16, 2003
Messages
339
Nice try arnelgp - that's and angle that I hadn't thought of.
Unfortunately, the solution hasn't worked either.
you can try this code:
Code:
Dim ctl As Control
Dim myTerm As String
myTerm = "Term " & CStr(ActiveControl.Column(4))
For Each ctl In Me.Controls
    If TypeOf ctl Is NavigationButton Then
        If ctl.Caption = myTerm Then
            ctl.SetFocus
            SendKeys "{ENTER}"
            Exit For
        End If
    End If
Next

edit: you can use the above code Alone, without using BrowseTo
Sorry = arnelgp, it seems I lied to you.
The code work, provided that I am not in the editor and trying to debug it.
If I am in the editor, then the sendkey line inserts another blank line in my sub.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:17
Joined
May 7, 2009
Messages
19,169
yes, do not run it on the editor, because
it will "sendkeys" to the "current" window.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:17
Joined
Feb 19, 2002
Messages
42,981
This is quite simple if you are using a normal tabbed form.

Me.tabCtlTransactions.Pages("pgIBC124").SetFocus

tabCtlTransactions is the name of the tab control. pgIBC124 is the name of the tab.

I doubt this works in a Navigation form but you can try it. I don't use Navigation forms because they don't load all the subforms so you cannot refer to any subform except the one you are looking at. Unless there is some reason you actually need something the "Navigation" form is doing for you, switch to using a main form with a tab control and subforms on the tab pages. As long as you name the tab control and pages with meaningful names, you can easily refer to them in code.
 

Users who are viewing this thread

Top Bottom