By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,455 Members | 2,157 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,455 IT Pros & Developers. It's quick & easy.

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

100+
P: 547
I would like to add the ribbon name using vba in my startup form. Is it possible

i have tried

Expand|Select|Wrap|Line Numbers
  1. 'Dim db As DAO.Database
  2. Dim rs As DAO.Recordset
  3. Dim RibbonName As String
  4. Set db = CurrentDb
  5. Set rs = db.OpenRecordset("usysribbons", dbOpenDynaset)
  6. RibbonName = "start2"
  7. Set db = Nothing
  8.  
any suggestions?
Nov 3 '13 #1

✓ answered by ADezii

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.

Share this Question
Share on Google+
5 Replies


ADezii
Expert 5K+
P: 8,597
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:
    Expand|Select|Wrap|Line Numbers
    1. Function LoadRibbons()
    2. Dim db As DAO.Database
    3. Dim rs As DAO.Recordset
    4.  
    5. Set db = Application.CurrentDb
    6. Set rs = CurrentDb.OpenRecordset("tblRibbons")
    7.  
    8. '[RibbonName] - {TEXT}
    9. '[RibbonXml] - {MEMO}
    10.  
    11. Do While Not rs.EOF
    12.   Application.LoadCustomUI rs("RibbonName").Value, rs("RibbonXML").Value
    13.     rs.MoveNext
    14. Loop
    15.  
    16. rs.Close
    17. Set rs = Nothing
    18. Set db = Nothing
    19. End Function
  3. Once the Custom Ribbons are loaded, assign to Form:
    Expand|Select|Wrap|Line Numbers
    1. Me.RibbonName = "Some Ribbon"
Nov 4 '13 #2

Expert 100+
P: 634
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
Nov 4 '13 #3

ADezii
Expert 5K+
P: 8,597
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.
Nov 4 '13 #4

100+
P: 547
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?
Nov 4 '13 #5

ADezii
Expert 5K+
P: 8,597
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.
Nov 4 '13 #6

Post your reply

Sign in to post your reply or Sign up for a free account.