Activating a tab in a navigation subform

liddlem

Registered User.
Local time
Today, 13:43
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.
 
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
 
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.
 
yes, do not run it on the editor, because
it will "sendkeys" to the "current" window.
 

Users who are viewing this thread

Back
Top Bottom