Week 16 – Creating Ribbons Part 2

CO5022 – Database Principles and Practice
Week 16 – Creating Ribbons Part 2
This week we continue to create a ribbon for the mountain database, so you should complete Week 15 first.
Adding a built-in group and element
1. Return to your ribbon xml and add this group tag
<group idMso = "GroupClipboard"/>
This will add the built in clipboard group. Place this before the forms group on your ribbon
2. Now create a new group called grpClose at the end of the ribbon and add the built-in command Close Database
by adding this tag inside the group.
<button idMso = "FileCloseDatabase"/>
Complete the xml for the label and size attributes as before. As it stands, you will obtain the built-in image for
this command which is rather boring and doesn’t stand out to the user. Add an image tag to use the built-in
image "MasterViewClose"
Adding custom images
If you want to add images of your own, the process is a bit more complex. Access 2013 allows you to store ribbon
images in a table, but it doesn’t support .png format with a transparent background, so images should be stored in
an external folder.
1. Download the images Walk.png and Mount.png from the module website. You may prefer to obtain or draw
your own – they are almost certain to be better than mine! The important thing is that they should have a
transparent background, so that they appear to float on the ribbon.
2. Find the folder with your database in it, create a subfolder Images and place the images there.
3. Remove the xml tag imageMso for the Mount button and replace it with the tags:getImage = "getImages" and tag = "Mount"
4. Now, download the file basFunctions.bas and in the VBA editor, import it as a new module. This has a series of
API calls which are needed for the code below to work. Geeks may care to examine the code but mere mortals
will just use it and accept that it is needed.
5. Add a VBA function getImages as shown below:Public Sub getImages(control As IRibbonControl, ByRef image)
Set image = LoadImage(CurrentProject.Path & "\Images\" & control.Tag & ".png")
End Sub
This code is designed for simplicity and it assumes that the images are in the Images folder, they have the same
names as the Tag tag and a .png file extension. If any of these three is different your code will need to be
amended accordingly.
6. Check that your Mount image displays when you reload the database.
7. Modify the XML tags for Walks to add its custom image and check that works as well.
Modifying the Quick Access Toolbar
1. The quick access toolbar appears at the top of the screen above the toolbar, add these tags immediately after
the ribbon tag at the beginning of the xml
<qat>
<documentControls>
<control idMso="Undo" />
<control idMso="Redo" />
<control idMso="FileSave" />
</documentControls>
</qat>
2. Check that Undo, Redo and Save appear on the Quick Access Toolbar.
1
CO5022 – Database Principles and Practice
Adding a search combo box
1. Create a new group with using the XML shown below:<group id = "grpSearch" label = "Search">
<comboBox id = "cboSearch" label = "Mountain"
getItemCount = "MountCount"
getItemLabel = "MountList"
onChange = "FindMount"/>
</group>
2. In your Ribbons module, add this line of code at the top:Dim rst As Recordset
3. Now add this procedure which counts the number of mountain names ready to fill the combo box
Public Sub MountCount(control As IRibbonControl, ByRef count)
Dim sql As String
sql = "SELECT Mount FROM vwMountains ORDER BY Mount"
Set rst = CurrentDb.OpenRecordset(sql)
rst.MoveLast
rst.MoveFirst
count = rst.RecordCount
End Sub
4. Add this procedure which fills the combo-box
Public Sub MountList(control As IRibbonControl, index As Integer, ByRef label)
label = rst("Mount")
rst.MoveNext
If (rst.EOF) Then rst.Close
End Sub
5. Add this procedure to find the mountain
Public Sub FindMount(control As IRibbonControl, text As String)
Dim frm As Form
Set frm = Forms!frmMountains
Set rst = frm.RecordsetClone
rst.MoveFirst
rst.FindFirst "Mount = """ & text & """"
If Not rst.EOF Then frm.Bookmark = rst.Bookmark
End Sub
Adding some Reports
1. Create three simple reports using the Wizards listing the Mountains, Groups and Walks. The layout is
unimportant, we are only concerned with the ribbon interface.
2. Create a new group called Reports
and three smaller (i.e. not large
buttons) to launch the reports
Your finished ribbon should look
something like this:Further Work
This is a reasonable basic ribbon for the forms, but it is not really suited to using with reports.
Create a generic ribbon for the reports – you won’t need the clipboard since you can’t edit a report but you would
want options to Print, set up the Page Layout etc
Resources
There is a list of control names for all the built-in controls in AccessRibbonControls.xls on the module website.
2