How to activate a ribbon? (1 Viewer)

KitaYama

Well-known member
Local time
Tomorrow, 08:08
Joined
Jan 6, 2022
Messages
1,489
I have a custom ribbon (OrdersRibbon) with StartFromScratch="true" which contains 9 tabs, each one filled with its groups and controls.
I added another ribbon (ReportsRibbon) with StartFromScratch="False". Then set this ribbon as the default ribbon for one of my reports. (Design view- Other Tab - Ribbon Name)

Every time I open the report, ReportsRibbon tab is added to my main ribbon. But I have to click the RepotsRibbon to show its controls.
How can I activate the ribbon when the reports opens? I simply want to show the reportsRibbon without the need of an extra click.

I really appreciate any kind of help.

Edit : A sample database that shows the situation is attached.
If you click rpt, the specified ribbon is added to existing ribbon. But It's not activated until you click it.
How can I make access show the new ribbon without a click.
 

Attachments

  • TestRibbon.accdb
    768 KB · Views: 238
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 16:08
Joined
Oct 29, 2018
Messages
21,358
Hi. Do you need the buttons on the first ribbon when you're viewing the report? If not, it might be easier to just use startfromscratch=true. Otherwise, you have two other options: SendKeys or the ActivateTab method.
 

KitaYama

Well-known member
Local time
Tomorrow, 08:08
Joined
Jan 6, 2022
Messages
1,489
Hi. Do you need the buttons on the first ribbon when you're viewing the report? If not, it might be easier to just use startfromscratch=true. Otherwise, you have two other options: SendKeys or the ActivateTab method.
Yes, I need the other ribbon too. Sometimes users have to check/search before mailing the report.
I had already checked ActivateTab, but it doesn't work and returns an error. I think because it's not a tab, but a ribbon.

I'll check once again and post the exact error message I receive.

Thanks.
 

KitaYama

Well-known member
Local time
Tomorrow, 08:08
Joined
Jan 6, 2022
Messages
1,489
This is a shortened sample of the ribbon :
XML:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="onFormRibbonLoad" loadImage="LoadImage">
    <ribbon startFromScratch="false">
        <tabs>
            <tab id="tab_Reports" getLabel="GetLabel" getVisible="GetVisible">
                <group id="grp_Reports" getLabel="GetLabel">
                    <button id="btn_PrintReport" size="large" getLabel="GetLabel" imageMso="PrintTitles" tag="RibbonName:=;inMenu:=;CustomPicture:=;CustomPicturePath:=" getScreentip="GetScreentip" onAction="OnActionButton"/>
                </group>
            </tab>
    </tabs>
  </ribbon>
</customUI>

I have this line of code in a public module:

Code:
Public OrdersRibbon As IRibbonUI
Public ReportsRibbon As IRibbonUI


On got Focus event I call a function to activate the tab.
This is the error I'm receiving :

3.png


I appreciate any further assist .
Thank you.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 16:08
Joined
Oct 29, 2018
Messages
21,358
This is a shortened sample of the ribbon :
XML:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="onFormRibbonLoad" loadImage="LoadImage">
    <ribbon startFromScratch="false">
        <tabs>
            <tab id="tab_Reports" getLabel="GetLabel" getVisible="GetVisible">
                <group id="grp_Reports" getLabel="GetLabel">
                    <button id="btn_PrintReport" size="large" getLabel="GetLabel" imageMso="PrintTitles" tag="RibbonName:=;inMenu:=;CustomPicture:=;CustomPicturePath:=" getScreentip="GetScreentip" onAction="OnActionButton"/>
                </group>
            </tab>
    </tabs>
  </ribbon>
</customUI>

I have this line of code in a public module:

Code:
Public OrdersRibbon As IRibbonUI
Public ReportsRibbon As IRibbonUI


On got Focus event I call a function to activate the tab.
This is the error I'm receiving :

View attachment 99712

I appreciate any further assist .
Thank you.
Hi. Can you show us the callback for onFormRibbonLoad?
 

KitaYama

Well-known member
Local time
Tomorrow, 08:08
Joined
Jan 6, 2022
Messages
1,489
Hi. Can you show us the callback for onFormRibbonLoad?

I only have this.
Code:
Sub onFormRibbonLoad(ribbon As IRibbonUI)
    ' Callbackname in XML File "onLoad"

    Set OrdersRibbon = ribbon
    Set ReportsRibbon = ribbon
   
    Filter_Only_Current_Records = False
    Filter_Only_Undelivered = True
    Selected_Text = ""
    Selected_Text_Len = 0
    Selected_Text_Start = 0
   
End Sub

The last section are several public variable I use them.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 07:08
Joined
May 7, 2009
Messages
19,169
i made an app that has a "common" Datasheet Tool tab.
when you open a form, the tab will get focus.
it is using the "old" switch tab code i have found
way way back years ago.
 

KitaYama

Well-known member
Local time
Tomorrow, 08:08
Joined
Jan 6, 2022
Messages
1,489
i made an app that has a "common" Datasheet Tool tab.
when you open a form, the tab will get focus.
it is using the "old" switch tab code i have found
way way back years ago.
@arnelgp It seems that you've done it in a whole different way. It takes a while to understand what you've done. I'll take a look and will come back to you as soon as I'm able to implement your solution.

Thanks for looking into this.
 

KitaYama

Well-known member
Local time
Tomorrow, 08:08
Joined
Jan 6, 2022
Messages
1,489
I added a sample database that shows the situation to my first post above #1.
If you click rpt, the specified ribbon is added to existing ribbon. But It's not activated until you click it.
How can I make access show the new ribbon without a click.

thank you.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 07:08
Joined
May 7, 2009
Messages
19,169
move your code to the Activate Event of your report.
 

KitaYama

Well-known member
Local time
Tomorrow, 08:08
Joined
Jan 6, 2022
Messages
1,489
move your code to the Activate Event of your report.
Still the same.
I don't think the event counts. The problem should be the structure of the code.

Thanks for your effort to solve this.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 07:08
Joined
May 7, 2009
Messages
19,169
why not "show" all custom Tabs and Hide/Show some of them on demand.
you open the "report" and/or the form in your database.
 

Attachments

  • TestRibbon.accdb
    1.2 MB · Views: 244
Last edited:

KitaYama

Well-known member
Local time
Tomorrow, 08:08
Joined
Jan 6, 2022
Messages
1,489
why not "show" all custom Tabs and Hide/Show some of them on demand.
you open the "report" and/or the form in your database.
That was how I did it first.
But the database has more than 40 reports. I got tired of adding the necessary code to show/hide the tab.
I simply thought if I make it an stand alone ribbon, and not a tab, and set it as reports' ribbon, Access will do the effort to show/hide it instead of my code. So I changed it to a ribbon, and not a tab.

But it seems Access shows/hides the ribbon, but is not able to bring it in front.
I think there's no way and I will go back to a tab.

I will write the necessary code in a sub in a module, then will call the sub from reports' On_Activate and On_Close events.

I really appreciate your efforts to solve this.
Million thanks.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 07:08
Joined
May 7, 2009
Messages
19,169
you can create a simple class and call it on the Load event (form or report).
so you only write minimal code for the 40 reports.
 

Attachments

  • TestRibbon.accdb
    1.4 MB · Views: 266

D_Walla

Member
Local time
Today, 23:08
Joined
Aug 1, 2021
Messages
32
On the off-chance that it might be helpful to you, or to so someone else who comes across this thread:

Code:
Sub ActivateTab()
    ActivateRibbonTab "Print"
End Sub
Private Function ActivateRibbonTab(ByVal TabName As String) As Boolean
    ' https://www.mrexcel.com/board/threads/activate-ribbon-tab-without-xml-or-api-calls.1052325/
    Const CHILDID_SELF = 0&, NAVDIR_FIRSTCHILD = 7&
    Const NAVDIR_LASTCHILD = 8&, NAVDIR_NEXT = 5&
    Dim accObj As IAccessible, i As Long, j As Long, lChildCount As Long
        
    Set accObj = Application.CommandBars("Ribbon")
    
    Set accObj = accObj.accNavigate(NAVDIR_LASTCHILD, CHILDID_SELF)
    Set accObj = accObj.accNavigate(NAVDIR_LASTCHILD, CHILDID_SELF)
    Set accObj = accObj.accNavigate(NAVDIR_LASTCHILD, CHILDID_SELF)
    Set accObj = accObj.accNavigate(NAVDIR_LASTCHILD, CHILDID_SELF)
    Set accObj = accObj.accNavigate(NAVDIR_LASTCHILD, CHILDID_SELF)
    Set accObj = accObj.accNavigate(NAVDIR_FIRSTCHILD, CHILDID_SELF)
    lChildCount = accObj.accChildCount
    Set accObj = accObj.accNavigate(NAVDIR_FIRSTCHILD, CHILDID_SELF)
    
    On Error Resume Next
    For i = 1 To lChildCount
        Set accObj = accObj.accNavigate(NAVDIR_NEXT, CHILDID_SELF)
        If UCase(accObj.accName(CHILDID_SELF)) = UCase("Ribbon Tabs") Then
            Set accObj = accObj.accNavigate(NAVDIR_FIRSTCHILD, CHILDID_SELF)
            lChildCount = accObj.accChildCount
            Set accObj = accObj.accNavigate(NAVDIR_FIRSTCHILD, CHILDID_SELF)
            For j = 1 To lChildCount
                Set accObj = accObj.accNavigate(NAVDIR_NEXT, CHILDID_SELF)
                If UCase(accObj.accName(CHILDID_SELF)) = UCase(TabName) Then
                    accObj.accDoDefaultAction CHILDID_SELF
                    ActivateRibbonTab = Not CBool(Err.Number)
                    Exit Function
                End If
            Next j
        End If
    Next i
End Function
 

KitaYama

Well-known member
Local time
Tomorrow, 08:08
Joined
Jan 6, 2022
Messages
1,489
On the off-chance that it might be helpful to you, or to so someone else who comes across this thread:

I can't make it work.

Test the attached file.
 

Attachments

  • TestRibbon.accdb
    768 KB · Views: 224

D_Walla

Member
Local time
Today, 23:08
Joined
Aug 1, 2021
Messages
32
Well, I can get it to switch between the Login and Print tabs easily enough, but for whatever reason, not to the Home Tab. I'll take a look on Monday when I'm back from the weekend.
 

KitaYama

Well-known member
Local time
Tomorrow, 08:08
Joined
Jan 6, 2022
Messages
1,489
Well, I can get it to switch between the Login and Print tabs easily enough, but for whatever reason, not to the Home Tab. I'll take a look on Monday when I'm back from the weekend.
Thank you.
 

Users who are viewing this thread

Top Bottom