0

I'm using mscomctl.ocx in 32 bit version of Access, but facing problems with the imagelist resorce when converting to 64bit Office 365 version of Access.

32bit version we are using this code (with imagelist):

Set cbItem = cmdBar.Controls.Add(1)
With cbItem
    .Caption = "Refresh"
    .OnAction = "=fuPub_ExRefresh()"
    .Picture = imgListComBar.ListImages("Refresh").Picture
    .enabled = True
End With

In 64 bit, is it possible to use something like this...

Set cbItem = cmdBar.Controls.Add(1)
With cbItem
    .Caption = "Refresh"
    .OnAction = "=fuPub_ExRefresh()"
    .Picture = ...some base64 string/object ??
    .enabled = True
End With
GSerg
  • 76,472
  • 17
  • 159
  • 346
WebCool
  • 11
  • 2

1 Answers1

0

The CommandBarButton.Picture property allows to set an IPictureDisp object representing the image of a CommandBarButton object.

Sub ChangeButtonImage() 
    Dim picPicture As IPictureDisp 
    Dim picMask As IPictureDisp 

    Set picPicture = stdole.StdFunctions.LoadPicture( _ 
        "c:\images\picture.bmp") 
    Set picMask = stdole.StdFunctions.LoadPicture( _ 
        "c:\images\mask.bmp") 

    'Reference the first button on the first command bar 
    'using a With...End With block. 
    With Application.CommandBars.FindControl(msoControlButton) 
        'Change the button image. 
        .Picture = picPicture 

        'Use the second image to define the area of the 
        'button that should be transparent. 
        .Mask = picMask 
    End With 
End Sub

You can try to restore an IPictureDisp interface from a base64 string. See Using base64 data stored in CustomXMLPart as image in Office for more information:

Type GUID
  Data1 As Long
  Data2 As Integer
  Data3 As Integer
  Data4(7) As Byte
End Type

Private Declare Function CreateStreamOnHGlobal Lib "ole32.dll" (ByRef hGlobal As Any,     ByVal fDeleteOnResume As Long, ByRef ppstr As Any) As Long
Private Declare Function OleLoadPicture Lib "olepro32.dll" (ByVal lpStream As IUnknown, ByVal lSize As Long, ByVal fRunMode As Long, ByRef riid As GUID, ByRef lplpObj As Any) As Long
Private Declare Function CLSIDFromString Lib "ole32.dll" (ByVal lpsz As Long, ByRef pclsid As GUID) As Long

Private Const SIPICTURE As String = "{7BF80980-BF32-101A-8BBB-00AA00300CAB}"

Public Function PictureFromArray(ByRef b() As Byte) As IPicture
  On Error GoTo errorhandler

  Dim istrm As IUnknown
  Dim tGuid As GUID

  If Not CreateStreamOnHGlobal(b(LBound(b)), False, istrm) Then
    CLSIDFromString StrPtr(SIPICTURE), tGuid
    OleLoadPicture istrm, UBound(b) - LBound(b) + 1, False, tGuid, PictureFromArray
  End If

  Set istrm = Nothing
  Exit Function
errorhandler:
  Debug.Print "Could not convert to IPicture!"
End Function
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45