User Defined Icons / Pictures In Ribbon Controls

You can use your own icons an pictures in Ribbon Controls. Instead of the callback imageMSO="xxx" you require "getImage" in Ribbon XML.

The Sample DB contains the function "getAppPath()" which is used to return the database folder and name, where also the icons and pictures are stored. File name including extension has been stored in attribute "tag" in the XML file.

Ribbon XML Synax:

<button id="MyButton"
        label="My Button"
        onAction="MyButtonCallbackOnAction" />


There are two options for callback "getImages" to load user-defined pictures:

Either with build-in Access functions (no transparency) :

Public Sub getImages(control As IRibbonControl, _
                     ByRef image)
' Loads a picture without transparency into the ribbon
' Only valid picture formats must be used (see OH).
    Set Image = LoadPicture(getAppPath & control.Tag)
'Or a ImageMso 
    image = "HappyFace" 
End Sub

or with GDI+ (the module "basGDI" is required. Transparency and multiple picture formats supported).

Public Sub getImages(control As IRibbonControl, _
                     ByRef image)
' Loads a picture with transparency into the ribbon
' The modul basGDI is required.
    Set image = LoadPictureGDIP(getAppPath & control.Tag)
'Or a ImageMso 
    image = "HappyFace" 
End Sub

Required Functions:

Additional function to be copied to a standard module:

Public Function getAppPath() As String     
' Returns the current database folder         
   getAppPath = Left(CurrentDb.Name, Len(CurrentDb.Name) _         
                - Len(Dir(CurrentDb.Name)))     
End Function

Module basGDI required for second example:

You can find this module in Sample DB 3 or the the module for Access 2007, Access 2010 x86, Access 2010 x64, Access 2013 x86 and Access 2013 x64.


The module originates from: Sascha Trowitzsch (German) .You can also load it from there. Otherwise you can adjust the sample project from ActiveVB.