Custom ribbon images (1 Viewer)

smig

Registered User.
Local time
Today, 03:45
Joined
Nov 25, 2009
Messages
2,209
Ribbon Creator is the software available at Gunter Avenius' site: https://www.accessribbon.de/en/?Ribbon_Creator



This is an extract from the ribbon XML from one of my apps

Code:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OnRibbonLoad" [B][COLOR="DarkRed"]loadImage="LoadImages"[/COLOR][/B]>
  <ribbon startFromScratch="false">
    <tabs>
      <tab id="tab1" label="Help" getVisible ="GetVisible" tag = "RibbonName:=Help;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=" > 
        <group id="grp0" autoScale="false" centerVertically="false" label="Info" getVisible ="GetVisible" tag = "RibbonName:=;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;CustomPicture:=;CustomPicturePath:=" >
          <button id="btn0" size="large" label="Getting Started" screentip="View the Getting Started Guide for this application" supertip=" " imageMso="HelpGettingStarted" tag="RibbonName:=Help;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;CustomPicture:=;CustomPicturePath:=" onAction="OnActionButton" getVisible="GetVisible" getEnabled="GetEnabled" />
          <button id="btn1" size="large" label="User Guide" screentip="View the User Guide for this application" supertip=" " imageMso="FileDocumentManagementInformation" tag="RibbonName:=Help;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;CustomPicture:=;CustomPicturePath:=" onAction="OnActionButton" getVisible="GetVisible" getEnabled="GetEnabled" />
        </group>
        <group id="grp1" autoScale="false" centerVertically="false" label="Support Tools" getVisible ="GetVisible" tag = "RibbonName:=;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;CustomPicture:=;CustomPicturePath:=" >
          <button id="btn2" size="large" label="Check for Updates" screentip="Check the program website for a newer version" supertip=" " imageMso="ProductUpdates" tag="RibbonName:=Help;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;CustomPicture:=;CustomPicturePath:=" onAction="OnActionButton" getVisible="GetVisible" getEnabled="GetEnabled" />
          <button id="btn3" size="large" label="Email Support" screentip="Send an email to customer support" supertip=" " imageMso="FileNewEmail" tag="RibbonName:=Help;inMenu:=;CustomTagValue1:=;CustomTagValue2:=;CustomTagValue3:=;CustomPicture:=;CustomPicturePath:=" onAction="OnActionButton" getVisible="GetVisible" getEnabled="GetEnabled" />
          <button id="btn4" size="large" label="Backup Database" screentip="Save a backup to the default folder" supertip=" " imageMso="BackupSite" ......... (etc) ....

I used the Ribbon Creator app to create this

FWIW, this is the ribbon
You can either use the loadImage="LoadImagesFunction" at the beginning, or use getImage="GetImagesFunction" for each icon require to be loaded.

Without seeing your LoadImages function it won't help me.

In your case all the icons are imageMso so they are taken from the Office Ribbon, and LoadImages is not used.

from 1st. paragraph here http://www.ribbons-access.com/ms-access/ribbon-creator-builder-and-editor-part-5.asp
"Remember that, to use the attribute image of the controls, you must use the attribute loadImage of the tag CustomUI, which calls the function fncLoadImage."
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:45
Joined
Oct 29, 2018
Messages
21,467
This one closed the issue :)
I'm now happily can use transparent PNG files :D
It was in the example, not in the code on the page.

Hi. Glad to hear you got it sorted out. Good luck with your project.
 

isladogs

MVP / VIP
Local time
Today, 01:45
Joined
Jan 14, 2017
Messages
18,212
You can either use the loadImage="LoadImagesFunction" at the beginning, or use getImage="GetImagesFunction" for each icon require to be loaded.

Without seeing your LoadImages function it won't help me.

In your case all the icons are imageMso so they are taken from the Office Ribbon, and LoadImages is not used.

from 1st. paragraph here http://www.ribbons-access.com/ms-access/ribbon-creator-builder-and-editor-part-5.asp
"Remember that, to use the attribute image of the controls, you must use the attribute loadImage of the tag CustomUI, which calls the function fncLoadImage."

Hi
Sorry - I sent it late at night...
Glad you now have a solution.
Anyway, the LoadImages function is part of Gunter Avenius' application. The code is:

Code:
Sub LoadImages(control, ByRef Image)
    ' Callbackname in XML File "loadImage"

    ' Loads an image with transparency to the ribbon
    ' Module basGDIPlus is required
      
    Dim strImage        As String
    Dim strPicture      As String
    
    strImage = CStr(control)
    strPicture = getPic(strImage)
    
    If strImage <> "" Then
        If bolUsePicturesFromTable = True Then
            If strPicture <> "" Then
                Set Image = getIconFromTable(strPicture)
            Else
                Set Image = Nothing
            End If
        Else
            Set Image = LoadPictureGDIP(strImage)
        End If
    Else
        Set Image = Nothing
    End If
    
End Sub

As you can see that depends on other related code. Rather than post all the code, I suggest you download the free evaluation version which I still use as that does all I've needed so far

Similarly rather than post the full code from another app with a custom .ico image, see the XML code by someone else in this UA forum post
https://www.utteraccess.com/forum/index.php?s=&showtopic=2055586&view=findpost&p=2733150

Hope that helps
 

smig

Registered User.
Local time
Today, 03:45
Joined
Nov 25, 2009
Messages
2,209
Hi
Sorry - I sent it late at night...
Glad you now have a solution.
Anyway, the LoadImages function is part of Gunter Avenius' application. The code is:

Code:
Sub LoadImages(control, ByRef Image)
    ' Callbackname in XML File "loadImage"

    ' Loads an image with transparency to the ribbon
    ' Module basGDIPlus is required
      
    Dim strImage        As String
    Dim strPicture      As String
    
    strImage = CStr(control)
    strPicture = getPic(strImage)
    
    If strImage <> "" Then
        If bolUsePicturesFromTable = True Then
            If strPicture <> "" Then
                Set Image = getIconFromTable(strPicture)
            Else
                Set Image = Nothing
            End If
        Else
            Set Image = LoadPictureGDIP(strImage)
        End If
    Else
        Set Image = Nothing
    End If
    
End Sub

As you can see that depends on other related code. Rather than post all the code, I suggest you download the free evaluation version which I still use as that does all I've needed so far

Similarly rather than post the full code from another app with a custom .ico image, see the XML code by someone else in this UA forum post
https://www.utteraccess.com/forum/index.php?s=&showtopic=2055586&view=findpost&p=2733150

Hope that helps
The code in the example I pointed to in Post #12 is much simpler :)
http://www.ribbons-access.com/ms-access/ribbon-creator-builder-and-editor-part-5.asp
He also saves the images in the table as attached files, which is much simpler to extract.

Now I'm only trying to find out how to extract several images that are stored in the same field of table :D
For now I only manage to extract the 1st one

This is the original code.
Code:
Public Function fncExtractImage(strImageName As String) As String
Dim strPath As String
Dim rsParent As DAO.Recordset
Dim rsChild As DAO.Recordset2
Dim flData As Field2
Dim flName As Field2

strPath = CurrentProject.Path & "\temp"

Set rsParent = CurrentDb.OpenRecordset("tblImagesRibbons")
Set rsChild = rsParent.Fields("imageRibbon").Value
Set flData = rsChild.Fields("filedata")
Set flName = rsChild.Fields("Filename")

If Len(Dir(strPath, vbDirectory + vbHidden) & "") = 0 Then
    FileSystem.MkDir (strPath)
    FileSystem.SetAttr strPath, vbHidden
End If

Do While Not rsChild.EOF
    If flName.Value = strImageName Then
        flData.SaveToFile (strPath)
        Exit Do
    End If
    rsChild.MoveNext
Loop
Set flNome = Nothing
Set flData = Nothing
Set rsChild = Nothing
Set rsParent = Nothing

fncExtractImage = strPath & "\" & strImageName

End Function
 

isladogs

MVP / VIP
Local time
Today, 01:45
Joined
Jan 14, 2017
Messages
18,212

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:45
Joined
Oct 29, 2018
Messages
21,467
The code in the example I pointed to in Post #12 is much simpler :)
http://www.ribbons-access.com/ms-access/ribbon-creator-builder-and-editor-part-5.asp
He also saves the images in the table as attached files, which is much simpler to extract.

Now I'm only trying to find out how to extract several images that are stored in the same field of table :D
For now I only manage to extract the 1st one

This is the original code.
Code:
Public Function fncExtractImage([COLOR=Red][B]strImageName [/B][/COLOR]As String) As String
Dim strPath As String
Dim rsParent As DAO.Recordset
Dim rsChild As DAO.Recordset2
Dim flData As Field2
Dim flName As Field2

strPath = CurrentProject.Path & "\temp"

Set rsParent = CurrentDb.OpenRecordset("tblImagesRibbons")
Set rsChild = rsParent.Fields("imageRibbon").Value
Set flData = rsChild.Fields("filedata")
Set flName = rsChild.Fields("Filename")

If Len(Dir(strPath, vbDirectory + vbHidden) & "") = 0 Then
    FileSystem.MkDir (strPath)
    FileSystem.SetAttr strPath, vbHidden
End If

Do While Not rsChild.EOF
    If flName.Value = strImageName Then
        flData.SaveToFile (strPath)
        [COLOR=red][B]Exit Do[/B][/COLOR]
    End If
    rsChild.MoveNext
Loop
Set flNome = Nothing
Set flData = Nothing
Set rsChild = Nothing
Set rsParent = Nothing

fncExtractImage = strPath & "\" & strImageName

End Function
Hi. The code you posted accepts a filename for the image to extract, which means it was designed to extract only one image out of the Attachment field. Otherwise, you would remove the filename argument and you wouldn't exit the loop while extracting the attachments.
 

smig

Registered User.
Local time
Today, 03:45
Joined
Nov 25, 2009
Messages
2,209
Fair enough but if you are talking about saving the files using an attachment field then I wouldn't recommend it even if it is simpler

Anyway good luck with your ribbon
Why don't you recommend using an attachment field?

The ribbon is working great, Thanks :)
 

smig

Registered User.
Local time
Today, 03:45
Joined
Nov 25, 2009
Messages
2,209
Hi. The code you posted accepts a filename for the image to extract, which means it was designed to extract only one image out of the Attachment field. Otherwise, you would remove the filename argument and you wouldn't exit the loop while extracting the attachments.

I see what you mean
How can I read the names of the attached files inside the field ?
is it flName = rsChild.Fields("Filename")
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:45
Joined
Oct 29, 2018
Messages
21,467
I see what you mean
How can I read the names of the attached files inside the field ?
is it flName = rsChild.Fields("Filename")
Hi. You don't have to, if the intent is to simply extract them all. Just loop through the attachments and extract away. This is already being done within the loop in the code you posted with the exception of checking for a matching filename and only extracting the one requested. So, in your version, you simply don't check.
 

June7

AWF VIP
Local time
Yesterday, 16:45
Joined
Mar 9, 2014
Messages
5,470
Saving objects in db uses up Access 2GB file size limit and you have to extract them to local folder anyway to do things like attach to email. Attachment field is a type of multi-value field. Multi-value fields are not supported by other db platforms so if you ever migrate, will have to extract files.
 

smig

Registered User.
Local time
Today, 03:45
Joined
Nov 25, 2009
Messages
2,209
Saving objects in db uses up Access 2GB file size limit and you have to extract them to local folder anyway to do things like attach to email. Attachment field is a type of multi-value field. Multi-value fields are not supported by other db platforms so if you ever migrate, will have to extract files.
Thanks for your comment

These are small icons, that takes 2mb only.
I already saved 50+ of them and they added almost nothing to my db size.

Normally they are on a local folder, and I don't extract them.
5 of them, which are imortent, will be checked and extracted on APP startup if the user deleted them from the folder. All the other, which are not mandatory will be only extracted if the user deleted the folder.

If I ever migrate I won't need this, as the user won't be able to delete the files.
 

smig

Registered User.
Local time
Today, 03:45
Joined
Nov 25, 2009
Messages
2,209
Hi. You don't have to, if the intent is to simply extract them all. Just loop through the attachments and extract away. This is already being done within the loop in the code you posted with the exception of checking for a matching filename and only extracting the one requested. So, in your version, you simply don't check.
Thanks

this is the code I'm using.
It works perfect now

The problem was it had the Exit Do command :D

(In one case I save 50+ images under the same "imageName")
Code:
Public Sub pbExtractImage(strImageName As String, strPath As String)

On Error GoTo errHere


Dim rsParent As DAO.Recordset
Dim rsChild As DAO.Recordset2
Dim flData As Field2

If fnCheckDirExist(strPath) = False Then
    Call pbCreateDirectory(strPath)
End If

Set rsParent = CurrentDb.OpenRecordset("SELECT * FROM [Images_Table] WHERE [ImageName] = '" & strImageName & "' ")
Set rsChild = rsParent.Fields("ImageData").Value
Set flData = rsChild.Fields("filedata")

With rsChild
    If .RecordCount > 0 Then
        .MoveFirst
        Do While Not .EOF
            flData.SaveToFile (strPath)
            .MoveNext
        Loop
    End If
    .Close
End With


ExitHere:
    Set flData = Nothing
    Set rsChild = Nothing
    Set rsParent = Nothing
    Exit Sub

errHere:
    Call ErrorHandling("mdl_AutoExec", "pbExtractImage", Err, Err.Description)
    Resume ExitHere

End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:45
Joined
Oct 29, 2018
Messages
21,467
Thanks

this is the code I'm using.
It works perfect now

The problem was it had the Exit Do command :D
Hi. That's why I highlighted that part in red in my earlier post. I'm glad you caught it now. Good luck with your project.
 

Users who are viewing this thread

Top Bottom