Table of Contents

In this post I will be showing you how to create custom labels for the Ribbon.

Featured Videos:

  • 07 – Get Label

Featured Downloads

  • AccessRibbon07

07 – Get Label

The Code

 

< customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"> 
  < ribbon startFromScratch="true"> 
    < tabs> 

      < tab id="tabHome" label="Home" visible="true"> 

     < group id="GroupInfo"  label="Info"> 
         < labelControl id="lblDate" getLabel="onGetLabel"/> 
          < labelControl id="lblUser" getLabel="onGetLabel"/> 
         < labelControl id="lblTerminal" getLabel="onGetLabel"/> 
      < /group>     

         < group id="GroupHome"  label="Home"> 
        < button id="cmdHome" label="Home" imageMso="BlogHomePage"
                size="large"   onAction="onClick"/>          
       < /group> 

        < group id="GroupNavigation"  label="Navigation"> 

        < splitButton id="sbStudents" size="large"> 
                < button id="cmdStudents"  imageMso="AddOrRemoveAttendees"
                  label="Students"  onAction="onClick"/> 
                         < menu id="menStudents"> 
            < button id="cmdStudentsNew" label="New Student" onAction="onClick"   imageMso="DiagramShapeInsertClassic" /> 
              < button id="cmdStudentsEdit" label="Edit Student" onAction="onClick"   imageMso="DataFormSource" /> 
               < button id="cmdStudentsReports" label="Reports" onAction="onClick"   imageMso="DefinedPrintStyle"/> 
                          < /menu> 
             < /splitButton> 

   < /group> 

      < /tab> 
    < /tabs> 
  < /ribbon> 
< /customUI>
Public Sub onGetLabel(control As IRibbonControl, ByRef label)

'-----------------Other Labels--------------------------------
Select Case control.id
Case "lblDate"
    label = FormatDateTime(Date, vbLongDate)
Case "lblUser"
    label = getAccessUserName()
Case "lblTerminal"
    label = getComputerName()

End Select
End Sub
Public Function getComputerName()

On Error GoTo ErrorHandler

getComputerName = "Terminal: " & Environ$("computername")

Exit_Function:
    Exit Function

ErrorHandler:
    getComputerName = "Unknown"
    Resume Exit_Function

End Function

Public Function getAccessUserName()

On Error GoTo ErrorHandler

getAccessUserName = "User: " & Environ$("username")

Exit_Function:
    Exit Function

ErrorHandler:
    getAccessUserName = "Unknown"
    Resume Exit_Function

End Function

Related Posts

01 – Introduction to the Ribbon
02 – Explanation of the Code
03 – The USysRibbons Table
04 – Tabs, Groups, Buttons and ImageMSOs
05 – Callbacks
06 – Split Buttons
08 – Drop Down Menus 1
09 – Drop Down Boxes 2
10 – Splitting a Database

Leave a Reply

Your email address will not be published. Required fields are marked *

Visit Us On TwitterVisit Us On FacebookVisit Us On Youtube