How to add the ribbon name with vba to the startup form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neelsfer
    Contributor
    • Oct 2010
    • 547

    How to add the ribbon name with vba to the startup form

    I would like to add the ribbon name using vba in my startup form. Is it possible

    i have tried

    Code:
    'Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim RibbonName As String
    Set db = CurrentDb
    Set rs = db.OpenRecordset("usysribbons", dbOpenDynaset)
    RibbonName = "start2"
    Set db = Nothing
    any suggestions?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    It is a little more complicated than that.
    1. To create and make the Ribbon available to Access, you first create a Module in the Database with a Procedure that calls the LoadCustomUI Method, passing to it a Ribbon Name and the well-formed XML. You can use any Table for this Procedure. You can make different Ribbons available by using multiple calls to the LoadCustomUI method, passing in different XML as long as the name of each Ribbon and the ID attribute of the tabs that make up the Ribbon are unique. After the procedure is complete, you then create an AutoExec macro that calls the Procedure by using the RunCode action. That way, when the application is started, the LoadCustomUI method is automatically executed and all of the custom Ribbons are made available to the Application.
    2. Sample Code executed via AutoExec Macro:
      Code:
      Function LoadRibbons()
      Dim db As DAO.Database
      Dim rs As DAO.Recordset
      
      Set db = Application.CurrentDb
      Set rs = CurrentDb.OpenRecordset("tblRibbons")
      
      '[RibbonName] - {TEXT}
      '[RibbonXml] - {MEMO}
      
      Do While Not rs.EOF
        Application.LoadCustomUI rs("RibbonName").Value, rs("RibbonXML").Value
          rs.MoveNext
      Loop
      
      rs.Close
      Set rs = Nothing
      Set db = Nothing
      End Function
    3. Once the Custom Ribbons are loaded, assign to Form:
      Code:
      Me.RibbonName = "Some Ribbon"

    Comment

    • MikeTheBike
      Recognized Expert Contributor
      • Jun 2007
      • 640

      #3
      Hi ADezii

      Is there any reason why this method of creating a Ribbon for use in the Application is better than defining the Ribbon in USysRibbons table?

      MTB

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        I think that the only advantage to this approach, MikeTheBike, is that Ribbons need not be defined solely within the context of the UsysRibbons Table. The XML Markup can come from a Recordset Object created from a Table, from a source external to the Database (such as an XML file that you must parse into a String), or from XML markup embedded directly inside of the procedure.

        Comment

        • neelsfer
          Contributor
          • Oct 2010
          • 547

          #5
          thx adezii for the trouble.
          As i understand it, i first create a new table ie "tblRibbons ", and add 2 fields called "RibbonName " and "RibbonXml" , add my "ribbon code" and "titles" to the fields, then call the module from my startup form?

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            That appears to be the correct sequence to me. The important point is that
            when the Application is started, the LoadCustomUI method is automatically executed and all of the Custom Ribbons are made available to the Application.

            Comment

            Working...