Search code examples
xmlms-accessribbon

pass parameter into ribbon when onLoad


I want to have two versions of ribbon. One for developer and one for regular users. For developer version, the custom group will be added to existing ribbon which can be done by

<ribbon startFromScratch="false">

For regular user, the custom group existing ribbon will not be available which can be done by

<ribbon startFromScratch="true">

I can implement it by two records in USysRibbons table and load deferent record when form OnLoad. Can I have one record only by passing flag into XML and use some logic line to set it?

Something like:

If Developer = true then

<ribbon startFromScratch="false">

Else

<ribbon startFromScratch="true">

End if


Solution

  • I don't think you can achieve this by using the build-in logic of the USysRibbons table. Instead of using USysRibbons, you could use another table (or just rename it) to store your Ribbon XML. Then write a VBA procedure that loads the XML from your own table and calls the Application.LoadCustomUI-method to use your XML for the ribbon. Within that procedure you can then process and modify the ribbon XML in any way you like. That procedure has to be called by the AutoExec macro to put the ribbon in place on startup.

    In your case you could use something like this code:

    yourRibbonXML = ... ' ( load xml from your table into yourRibbonXML )
    
    If Developer = True then
        yourRibbonXML = Replace(yourRibbonXML, "startFromScratch=""true""", "startFromScratch=""false""")
    End if
    
    Application.LoadCustomUI "yourRibbonName", yourRibbonXML
    

    See this link for more detailed explainations: http://www.accessribbon.de/en/?Access_-_Ribbons:Load_Ribbons_Into_The_Database:..._Using_Any_User_Table