Document Tabs - How to set focus or hide? (1 Viewer)

john843

New member
Local time
Today, 14:26
Joined
Nov 26, 2023
Messages
5
RE: File > Options > Current Database > Application Options > Tabbed Documents + Display Document tabs

We have an Access application that can have have several Document Tabs open at a time.

How do I hide, set focus, reorder, and otherwise control these Document Tabs?

Thinking it's a application object, I've tried things like Application.Forms.GoToPage "MyForm" but no luck.
 

john843

New member
Local time
Today, 14:26
Joined
Nov 26, 2023
Messages
5
Using search term "Access – VBA – Set Focus On Specific Document Tab" I found this:

Code:
Public Function MDIClient_SwitchObject(sObjectName As String, sClass As String) As Boolean
    On Error GoTo Error_Handler
    Dim oUIA                  As UIAutomationClient.CUIAutomation
    Dim oAccess               As UIAutomationClient.IUIAutomationElement
    Dim oCondition            As UIAutomationClient.IUIAutomationCondition
    Dim oObject               As UIAutomationClient.IUIAutomationElement

    Set oUIA = New CUIAutomation
    Set oAccess = oUIA.ElementFromHandle(ByVal Application.hWndAccessApp)
    If Not (oAccess Is Nothing) Then
        Set oCondition = oUIA.CreateAndCondition(oUIA.CreatePropertyCondition(UIA_NamePropertyId, sObjectName), _
                                                 oUIA.CreatePropertyCondition(UIA_ClassNamePropertyId, sClass))
        Set oObject = oAccess.FindFirst(TreeScope_Subtree, oCondition)
        If Not (oObject Is Nothing) Then
            oObject.SetFocus
            MDIClient_SwitchObject = True
        Else
            Debug.Print "'" & sObjectName & "' not found."
        End If
    Else
        Debug.Print "Can't locate the database windows."
    End If
Error_Handler_Exit:
    On Error Resume Next
    If Not oObject Is Nothing Then Set oObject = Nothing
    If Not oCondition Is Nothing Then Set oCondition = Nothing
    If Not oAccess Is Nothing Then Set oAccess = Nothing
    If Not oUIA Is Nothing Then Set oUIA = Nothing
    Exit Function
Error_Handler:
    MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: MDIClient_SwitchObject" & vbCrLf & _
           "Error Description: " & Err.Description & _
           Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
           , vbOKOnly + vbCritical, "An Error has Occured!"
    Resume Error_Handler_Exit
End Function

!! Is this really necessary?
 

cheekybuddha

AWF VIP
Local time
Today, 20:26
Joined
Jul 21, 2014
Messages
2,280
Have you tried just setting focus to a control on the desired form?
Code:
Forms.NameOfFormToSwitchTo.NameOfControlOnForm.SetFocus
 

mike60smart

Registered User.
Local time
Today, 20:26
Joined
Aug 6, 2017
Messages
1,908
RE: File > Options > Current Database > Application Options > Tabbed Documents + Display Document tabs

We have an Access application that can have have several Document Tabs open at a time.

How do I hide, set focus, reorder, and otherwise control these Document Tabs?

Thinking it's a application object, I've tried things like Application.Forms.GoToPage "MyForm" but no luck.
Hi John
Usual process when you navigate to a New Tab you would close the Current Tab.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:26
Joined
Feb 19, 2002
Messages
43,280
I dislike the tab view and so never use it. I have a strong preference to allow the user to interact with one and only one form at a time. So, from the menu, a form opens and the menu hides itself. When the user is finished with the current form, he closes it and the menu reopens. Sometimes a form will open a popup. In this case, I may leave the original form visible but I open the popup as a dialog so that the user needs to close the popup before doing anything else with the first form.
 

john843

New member
Local time
Today, 14:26
Joined
Nov 26, 2023
Messages
5
Here's what I came up with:

Code:
Private Sub Form_Open(Cancel As Integer)
    On Error Resume Next
    DoCmd.OpenForm "frm1"
    DoCmd.OpenForm "frm2"
    DoCmd.OpenForm "frm3"
    . . .
    DoEvents
    DoCmd.OpenForm "frm1"
End Sub

I created a startup form which is launched when the app is opened.
(File > Options > Current Database > Application Options > Display Form)
The Tabs will appear in the order they are opened from left to right.
Then I "set focus" on frm1, which closes my startup form with code in Form_Load.

Once everything is opened, the ad hoc Doc Tabs will stack on the right.
Still experimenting with ways to hide/unhide. Thanks David for the set focus tip!
 

Users who are viewing this thread

Top Bottom