How to hide built in ribbons (1 Viewer)

Ari

Registered User.
Local time
Today, 01:20
Joined
Oct 22, 2011
Messages
139
Hi

PROBLEMS:
  • Can't find a way to hide the HomeTab. Yes, but his menu will be stuck in Add_ins guide.
  • If I recrate all my menus from scratch and move to Ribbons, is there a way to hide part of the menu, based on the user opened the App ? ie, Can I hide part of it after loading ? Yes, you should learn how to use getVisible attribute, as said Speakers_86. Download the sample RibbonGetVisible.zip the link below:
http://www.ribbons-access.com/downloads.asp
 

smig

Registered User.
Local time
Today, 11:20
Joined
Nov 25, 2009
Messages
2,209
Thanks, ill wait for your test.
Is there a way to see the names of the tabs ?
 

speakers_86

Registered User.
Local time
Today, 04:20
Joined
May 17, 2007
Messages
1,919
I don't think there is a way for the tab's label to NOT be there.

@Ari, what do you mean by that Add_ins bit?
 

smig

Registered User.
Local time
Today, 11:20
Joined
Nov 25, 2009
Messages
2,209
Forgive me for asking so many questions about the ribbons.
I'm realy getting lost here, and MS help is a little help only. It will probably be more helpfull for the ones who already know what to do :banghead:

I use this XML file:
Code:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <ribbon  startFromScratch="true">
        <tabs>
	<tab id = "tbTest1" label = "TAB test 1">
		<group id = "grpTest1" label = "Group Test 2">
			<button id = "btnTest1" imageMso = "StartAfterPrevious" label = "BTN 1"/>
		</group>
	</tab>
        </tabs>
    </ribbon>
</customUI>

I use this code to load the ribbon:
Code:
Public Sub LoadRibbons()

Dim strImportDir As String
Dim strImportFileName As String
Dim strTxtLine As String
Dim strRibbon As String

strImportDir = CurrentDBPath() & "\"
strImportFileName = "MyRibbonName.xml"

If Dir(strImportDir & strImportFileName) <> strImportFileName Then
    MsgBox "No XML file"
    GoTo ExitHere
End If

Open strImportDir & strImportFileName For Input As #1

Do While Not EOF(1)
    Line Input #1, strTxtLine
    Debug.Print strTxtLine
    strRibbon = strRibbon & strTxtLine
Loop

Close #1

Application.LoadCustomUI "MyAppRibbon_1", strRibbon


ExitHere:

End Sub

How do I make this ribbon active and visible ?
Will it hide all the BuiltIn Access Tabs, Including Home and File ones ?
 

speakers_86

Registered User.
Local time
Today, 04:20
Joined
May 17, 2007
Messages
1,919
Heres going above and beyond...
 

Attachments

  • Database1.mdb
    296 KB · Views: 210

smig

Registered User.
Local time
Today, 11:20
Joined
Nov 25, 2009
Messages
2,209
Thank you :)
This is realy great
Still not sure how you hide the Home tab and how this Invalidate thing work.

Can I also hide the File-Print and File-Privacy Options? Also the QuickAccessToolBar
 

speakers_86

Registered User.
Local time
Today, 04:20
Joined
May 17, 2007
Messages
1,919
Invalidate is our way of telling the ribbon to refresh itself. It is a method of the IRibbonUI object. That is why we have to use the reference. All of those get subs are called by the ribbon interface every time we invalidate. We don't actually call it ourselves.
 

smig

Registered User.
Local time
Today, 11:20
Joined
Nov 25, 2009
Messages
2,209
I think I start to get the idea :)
But, when you call the SetVisible(boo As Boolean) how does the IRibbonUI object know to invoke the getVisible() function and not the getSize() one ?
And how does it know what to do when you call the Invalidate() sub ?

I added a Debug.Print control.Id line to the getVisible() sub. All I get are the HelloIAmAButton and TabHomeAccess. Why is that ? How come this all thing only refer to these two?


Is there any specific reason why you kept it as MDB ?

*** Edit 1 ***
After Looking at the XML I think I understand it better. Correct me if I'm wrong :)
The Get subs are called by what you set in the XML

*** Edit 2 ***
If I call Invalidate in the Autoexec module or in my LogIn form's .onLoad it raise an error: 91 - Object vaiable or With Bloack variable not set. If I call it under a button's .onClick event it works :eek:


Thanks again,
Tal
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:20
Joined
May 7, 2009
Messages
19,248
as I have said, there is no way to hide the backstage.
 

speakers_86

Registered User.
Local time
Today, 04:20
Joined
May 17, 2007
Messages
1,919
I think I start to get the idea :)
But, when you call the SetVisible(boo As Boolean) how does the IRibbonUI object know to invoke the getVisible() function and not the getSize() one ?
And how does it know what to do when you call the Invalidate() sub ?

I added a Debug.Print control.Id line to the getVisible() sub. All I get are the HelloIAmAButton and TabHomeAccess. Why is that ? How come this all thing only refer to these two?


Is there any specific reason why you kept it as MDB ?

*** Edit 1 ***
After Looking at the XML I think I understand it better. Correct me if I'm wrong :)
The Get subs are called by what you set in the XML

*** Edit 2 ***
If I call Invalidate in the Autoexec module or in my LogIn form's .onLoad it raise an error: 91 - Object vaiable or With Bloack variable not set. If I call it under a button's .onClick event it works :eek:


Thanks again,
Tal

The get subs are called by the xml. The set subs are called by us via vba. The only thing the set subs do is set a variable and tell the ribbon to invalidate (which forces the get subs to run). Everything about this dynamic ribbon hinges on the variables.

Anytime you get error 91 it is because the you don't have a reference to the ribbon yet. I think I called it objRibbonName. Access is telling you that variable is not set. Access is real finnicky about this variable. It is set in the onLoad event of the ribbon, and we have no control over it. If we have an unhandled error, that variable is lost until we restart access. In your case, you are using the variable before the onLoad has run or before it has completed running. Since these are callbacks, I presume they are asyncronous, so timing can be an issue.
 

smig

Registered User.
Local time
Today, 11:20
Joined
Nov 25, 2009
Messages
2,209
Thanks :)
I have most of the things work as I want now.
I managed to disable al the Print options in the File Tab. Couldn't hide them though.

How do I hide or dissable the Access quick ToolBar ?
 

speakers_86

Registered User.
Local time
Today, 04:20
Joined
May 17, 2007
Messages
1,919
Check this out. That website is the best resource on the whole internet for ribbon stuff. Also, if you disable all those command in the xml in my sample you can almost lock down most of the things end users don't need access to.
 

smig

Registered User.
Local time
Today, 11:20
Joined
Nov 25, 2009
Messages
2,209
Thanks
Seems there is no way to Hide or disable the QAT, only to create your oun.
If you lock accessing to the main window in startup users can't customize it while running the app.

I'll keep digging into the ribbons :)
 

speakers_86

Registered User.
Local time
Today, 04:20
Joined
May 17, 2007
Messages
1,919
I think the start from scratch command disables qat. I've locked down stuff before and there is nothing harmful in the QAT.
 

smig

Registered User.
Local time
Today, 11:20
Joined
Nov 25, 2009
Messages
2,209
I think the start from scratch command disables qat. I've locked down stuff before and there is nothing harmful in the QAT.
Yes you are right. Start for scratch will lock the QAT, but looking at the site you gave me I saw you can still customize it to your needs.

Now I'm stuck with the Visinle thing :(
Trying to use the GetVisible and SetVisible code to hide some ribbons groups and command:
Code:
Public Sub getVisible(control As IRibbonControl, ByRef visible)
    
    On Error GoTo err
    
    
Select Case control.ID
    Case "TabHomeAccess"
        visible = booHomeTab
    Case Else
        visible = booVisible
End Select
    
    Exit Sub

err:
    'reporterror err.Number, err.Description, "Module1 | getVisible"
    Debug.Print err.Description
End Sub

Public Sub SetVisible(strCntrl As String, boo As Boolean)
    booVisible = boo
    objRibbonName.Invalidate
'    objRibbonName.InvalidateControl (strCntrl)
End Sub
This part is my LogIn form routines:
Code:
Select Case GetAppID()
    Case 1
        Call SetVisible("cmdPrintScheduleReport", False)
        Call SetVisible("cmdWeekSchedule", False)
        Call SetVisible("grpReports2", False)        ' -- Create Your Query
        Call SetVisible("cmdNoWorkDays", False)
        Call SetVisible("cmdMachshirim", False)
        Call SetVisible("cmdLoButza", False)
        Call SetVisible("cmdJoinMachshirim", False)
        Call SetVisible("cmdSetupTimeTable", False)
    Case 2
        Call SetVisible("grpReports2", False)        ' -- Create Your Query
        Call SetVisible("cmdMachshirim", False)
        Call SetVisible("cmdJoinMachshirim", False)
    Case Else
End Select

But it seems the tabs will be validated only when I try to go into them so they will hide all groups and commands that has the GetVisible="GetVisible" option in the XML and not only the ones I want to hide.
Is there a way to use the functions the way I do or do I need to create a public var for any specific command I might want to hide ?
As you can see in my code I tried both to validate the entire ribbon or the specific command.

Thanks,
Tal
 

speakers_86

Registered User.
Local time
Today, 04:20
Joined
May 17, 2007
Messages
1,919
The sample I posted is only designed to work with one dynamic object. If you have mulitple dynamic objects, you have to start expanding the code. You are using the booVisible variable for everything. That will cause issues. You need to separate variables to store the visible status of various objects. Here is what I would do assuming we have two buttons.

Code:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="LoadYoStuffFoo">
  <ribbon>
    <tabs>
       <tab id="tabMain" label="Your Tab Label" insertBeforeMso="TabHomeAccess">
              <group id="grpYourGroup" label="Your Custom Group">
                    <button id="btnFirst" 
                                    label="btnFirst"                      
                                    getVisible="getVisible"/>
                     <button id="btnSecond"
                                    getVisible="getVisible"
                                    label="btnSecond"/>
               </group>
         </tab>
    </tabs>
  </ribbon>
</customUI>

Your code would call this:
Code:
Private booBtnFirstVisible as boolean
Private booBtnSecondVisible as boolean

Public Sub SetBtnFirstVisible(boo As Boolean)
    booBtnFirstVisible = boo
    objRibbonName.InvalidateControl ("btnFirst")
End Sub

Public Sub SetBtnSecondVisible(boo As Boolean)
    booBtnSecondVisible = boo
    objRibbonName.InvalidateControl ("btnSecond")
End Sub

And your xml would call this:

Code:
Public Sub getVisible(control As IRibbonControl, ByRef visible)
    
    On Error GoTo err
    Select Case control.Id
        Case "btnfirst"
            visible = booBtnFirstVisible
        Case "btnsecond"
            visible = booBtnSecondVisible
        Case Else
            visible = True
            Debug.Print "missing case in getVisible: " & control.Id
    End Select
    Exit Sub
err:
    Debug.Print err.Description
End Sub
 
Last edited:

smig

Registered User.
Local time
Today, 11:20
Joined
Nov 25, 2009
Messages
2,209
Thanks
I was afraid using only the boo var is not possible.
I will use one Sub and one Function but will expand them similar to the OnAction one.
 

smig

Registered User.
Local time
Today, 11:20
Joined
Nov 25, 2009
Messages
2,209
Thank for all the help :)
All works very well now.
BackStage original elemnts are not visible anymore. I now try to customize it to my needs.

Is there any way to create a PopUp menu or these can be done in old style only?
 

Users who are viewing this thread

Top Bottom