Customizing a Ribbon

A

Alain

Hi to all,

I am playing around with the ribbons and i want to know if it is possible to
change the image of a regular Access button ?
I am trying with this code and no results, I just want to see the Acrobat
Reader icon instead of the one provided by Access

PS the rest of the XML code is just working fine.

<group id="grpPrint" label="Print" visible="true">
<button idMso="PublishToPdfOrEdoc" size="large" label="Save As PDF"
getImage="GetImages" tag="AcroReader.ico"
supertip="Save this document as .pdf"/>
</group>
 
A

Albert D. Kallal

You don't post what your custom getImages code looks like.

You most certanly can replace that buttons image to whatever you want.


<group id="grpPrint" label="Print" visible="true">
<button idMso="PublishToPdfOrEdoc" size="large" label="Save As PDF"
getImage="GetImages" tag="AcroReader.ico"
supertip="Save this document as .pdf"/>
 
A

Albert D. Kallal

sorry, bumped send key...

<button idMso="PublishToPdfOrEdoc" size="large" label="Save As PDF"
getImage="GetImages" tag="AcroReader.ico"
supertip="Save this document as .pdf"/>
</group>

Also, since you not changing the image at runtime, then you best use

image="AcroReader.ico"

You thus have to put into the ribbons heading a global image loader routine.
hence:


<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
loadImage="CallBackLoadImage">

<ribbon startFromScratch="true">
 
A

Albert D. Kallal

sorry, bumped send 3nd time....

<button idMso="PublishToPdfOrEdoc" size="large" label="Save As PDF"
getImage="GetImages" tag="AcroReader.ico"
supertip="Save this document as .pdf"/>

In above you are using getImage. Since you are not changing the image at
runtime, then you best use the option for a "one time" load of the image.
So, replace above with:

image="AcroReader.ico"

Using image in place of getImage means that you have to put into the ribbons
heading a global image loader routine

hence:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"

loadImage="CallBackLoadImage"> <--- add this

<ribbon startFromScratch="true">

Note carfull how
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">

becomes: (I moved the end ">" to the next line)

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"

loadImage="CallBackLoadImage"> <--- add this

<ribbon startFromScratch="true">


You callback routine for loading the image will be:

Sub CallbackLoadImage(strImage As String, _
ByRef image)

Dim strImagePath As String

strImagePath = CurrentProject.Path & "\ & strImage
Set image = LoadPicture(strImagePath)

End Sub

The above assumes the icon is going to be in the same dir of the front end
access application

If for some reason you don't want to setup a "global" image loader, then you
CAN use your "getImage" approach. So, if you have:

getImage="GetImages" tag="AcroReader.ico"


Your custom image loader will then be:

Public Sub MyImage(control As IRibbonControl, ByRef image)

Dim f As Form
Dim strImagePath As String
Dim strImage As String

On Error GoTo MyImage_Error

strImage = control.Tag
strImagePath = CurrentProject.Path & "\" & strImage
Set image = LoadPicture(strImagePath)

End Sub

As mentioned, you really don't need nor want to use "getImage" in the
ribbon. This forces you to use the "tag", and this ribbon attribute is
really only for if you need to change pictures/icons in the ribbon at RUN
TIME with VBA as opposed to at ribbon load-time "once". So, my first example
is the preference here. Both approaches should work however.
 
A

Alain

Hi Albert,

this is the complete code I use for this:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="true">
<tabs>
<tab id="tabPrintPreview" label="Preview and Print">
<group id="grpPrint" label="Print" visible="true">
<button idMso="PrintDialogAccess" size="large"
label="Print" imageMso="PrintDialogAccess"/>
<button idMso="PublishToPdfOrEdoc" size="large"
label="Save As PDF"
getImage="GetImages" tag="AcroReader.ico"
supertip="Save this document as .pdf"/>
</group>
<group id="grpZoom" label="Zoom" visible="true">
<splitButton idMso="PrintPreviewZoomMenu" size="large"/>
<toggleButton idMso="ZoomFitToWindow" size="large"/>
<toggleButton idMso="PrintPreviewZoomTwoPages"
size="large"/>
</group>
<group id="grpClosePreview" label="Close Preview"
visible="true">
<button idMso="PrintPreviewClose" size="large"
label="Close Preview" imageMso="PrintPreviewClose"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

The icon image is being saved in a table in a binary format so it is always
with the db:
Public Sub GetImages(control As IRibbonControl, ByRef image)
'Callbackname in XML File "getImages"

Set image = getIconFromTable(control.Tag)

End Sub
Public Function getIconFromTable(strFilename As String) As Picture

Dim LSize As Long
Dim arrBin() As Byte
Dim rs As DAO.Recordset
Dim strSelectFile As String

On Error GoTo Errr

Set rs = DBEngine(0)(0).OpenRecordset("tblBinary", dbOpenDynaset)
rs.FindFirst "[FileName]='" & strFilename & "'"
If rs.NoMatch Then
Err.Raise vbObjectError + 5, "mdlBinary", _
"This file " & strFilename & " does not exist in
the table 'tblBinary!'"
Else
LSize = rs.Fields("binary").FieldSize - 1
ReDim arrBin(LSize)
arrBin = rs.Fields("binary")
Set getIconFromTable = ArrayToPicture(arrBin)
End If
rs.Close

fExit:
Reset
Erase arrBin
Set rs = Nothing
Exit Function
Errr:
MsgBox Err.Description
Resume fExit
End Function

This ribbon will be loaded everytime any report is being opened therefore,
if I understand you, using a global image loader will load the image once for
all the duration of the opened ribbon ? I think I understand if it is being
use for 1 image for a ribbon, but what about if I have 3 custom image per 1
specific ribbon, does the global image loader still do the same job ?, Please
keep in mind this is the first time I play with this ribbon stuff and quite
frankly, the reading I got from MS is not always quite clear.

Thanks
 
A

Albert D. Kallal

This ribbon will be loaded everytime any report is being opened therefore,
if I understand you, using a global image loader will load the image once
for
all the duration of the opened ribbon ?

correct. If you have 15 reports, and they all specify/use the same one
ribbon, then after the FIRST report is viewed, the ribbon is cached in
memory, and the call back does NOT get fired again if you use the image
attribute. So, everything only runs once. The additional advantage is
that you don't mess with the "tag" feature. Using the tag feature is a
bit of a kluge here. The tag idea is used in place of having some forms
start code run to load the ribbon, and NOT place the actual icon name
in the ribbon code (so, we use tag as a work around).

As mentioned, you can use either approach. The ribbon is cached only ONCE
in both cases, but using getImagee means that VBA code will be called EACH
TIME the ribbon is used in a report. Using the image approach means this
VBA code is run ONLY one time at first load. (because the ribbon code
knows that image is a one-time load where as getImage is desinged for
being changed on the "fly" in code. If your code ever needs to change
a icon image during program run time, then you have to use getImage.
I think I understand if it is being
use for 1 image for a ribbon, but what about if I have 3 custom image per
1
specific ribbon, does the global image loader still do the same job ?

Yes, that is correct.
, Please
keep in mind this is the first time I play with this ribbon stuff and
quite
frankly, the reading I got from MS is not always quite clear.

Actually, I don't think I read anywhere as to an explain as to why to use
one approach or the other. It one of those things that kind of needs to be
pointed out. For example, I don't think I ever read when it is better to
use a combo box, or list box.

Anyway, your code should work as you have it now. I not tried it, but I am
curious as to how you are you placing the icons into that table? I am
actually interested in your approach as then I not have to have an external
file/folder with icons in it as I do now.
 
A

Alain

Thanks,

I actually got the idea from www.accessribbon.de for the binary table , with
some minor modif, it does the job I need, not having a folder ouside the db
to keep my picture/icons.......
 
A

Albert D. Kallal

Alain said:
Thanks,

I actually got the idea from www.accessribbon.de for the binary table ,
with
some minor modif, it does the job I need, not having a folder ouside the
db
to keep my picture/icons.......

Thanks....that above ribbon link is a GREAT reference...#1 spot for access
people working with the ribbon....

I am wondering if the above supports transparency. I use the loadimageGDI
routines from that site else the icons look like crap when they are loaded
into the ribbon....

Anyway, I going to give your code example a try....I like/want to use the
icons in a table approach here also... (so, thank you!!).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top