Extracting the images in Access Image Gallery

aref

New member
Local time
Today, 00:11
Joined
Jan 10, 2023
Messages
28
Hi

I have a lot of images stored in Access Gallery.

Now I want to extract the desired image in D drive using coding.

please guide me. Thanks
 
Hi
 

Attachments

  • Gallery.jpg
    Gallery.jpg
    34.2 KB · Views: 207
Those images are stored in a system table called MSysResources, so you should be able to get them from there.
 
Oh, learned something new - never knew about this. The images are in an Attachment type field in MSysResources. Extract as you would any Attachment type field. Can query the table:

SELECT * FROM MSysResources;
 
This "feature" is very well hidden. You don't even see the gallery option unless you paste an image onto a form. Like all images, these will also bloat the database so use with caution.

Has anyone tried adding the images directly to MSysRecources? Do they then show up in the gallery?
 
I just tried it too and checked to see if you can delete them also. It appears you may need to restart access in order to update the gallery.
 
Hello, thank you for your kindness. It was great.

I have another question?

When an image is embedded in the form, where is this image stored and accessible?
 
embedded
 

Attachments

  • image_2023-09-16_141857209.png
    image_2023-09-16_141857209.png
    9.1 KB · Views: 125
Hello, thank you for your kindness. It was great.

I have another question?

When an image is embedded in the form, where is this image stored and accessible?
The only way I know how to get a copy of the embedded image is by exporting the form to XML.
 
See solution
Code:
Public Function savePictInForm(frm As Access.Form)
    Dim fname As String 'The name of the file to save the picture to
    Dim pngImage As String 'Stores the image data as a string
    Dim iFileNum As Double
    
    fname = CurrentProject.Path & "\Temp.png"
  
    iFileNum = FreeFile 'The next free file from the file systemc
    pngImage = StrConv(frm.PictureData, vbUnicode) 'Convert the byte array to a string
    MsgBox "Saved to: " & fname
    'Writes the string to the file
    Open fname For Binary Access Write As iFileNum
        Put #iFileNum, , pngImage
    Close #iFileNum
End Function
Public Function savePictInControl(ctrl As Access.Control)
    Dim filename As String 'The name of the file to save the picture to
    Dim strImage As String 'Stores the image data as a string
    Dim iFileNum As Double
    Dim realName As String
    realName = ctrl.Picture
    filename = CurrentProject.Path & "\" & realName
  
    iFileNum = FreeFile 'The next free file from the file systemc
    strImage = StrConv(ctrl.PictureData, vbUnicode) 'Convert the byte array to a string
    Debug.Print pngImage
    MsgBox "Saved to: " & filename
    'Writes the string to the file
    Open filename For Binary Access Write As iFileNum
        Put #iFileNum, , strImage
    Close #iFileNum
End Function
 
You can also change the embedded image (in the form) from embedded to shared, then it will be stored in MSysResources.
 
That may be true but I thought the point of the gallery was to make the storage of embedded images more efficient. So, if you have the same image used on several forms, is it stored ONCE in MSysResources or is it actually embedded with the form and so stored multiple times.?
 
You can also change the embedded image (in the form) from embedded to shared, then it will be stored in MSysResources.
I have tried this....The record gets saved into MSysResources but is doesn't get and Extension and when double clicking the attachment field the file is not recognized.
Any ideas? Thanks for your help

Screenshot 2024-03-11 151024.png


Screenshot 2.png
 
you use "another" code to extract Images from MsysResources table.
Code:
Option Compare Database
Option Explicit

Public Sub subExtractImageFromMsys()

    Dim db As DAO.Database
    Dim rs_p As DAO.Recordset2
    Dim rs_c As DAO.Recordset2
    
    Dim sPath As String
    Dim sFile As String
    
    sPath = CurrentProject.Path & "\Images\"
    
    Set db = CurrentDb
    
    Set rs_p = db.OpenRecordset("select * from MsysResources where [type]='img';", dbOpenDynaset)
    
    With rs_p
        If Not (.BOF And .EOF) Then
            .MoveFirst
            
            subForceMKDir sPath
            
        
            Do Until .EOF
                Set rs_c = .Fields("Data").Value
                
                sFile = sPath & .Fields("Name") & "." & .Fields("Extension")
                If Len(Dir$(sFile)) <> 0 Then
                    Kill sFile
                End If
                
                rs_c.Fields("FileData").SaveToFile sFile
            
                Set rs_c = Nothing
                
                .MoveNext
            Loop
            MsgBox "Done extracting Images to " & sPath
        End If
        .Close
    End With
    
    Set rs_p = Nothing
    Set db = Nothing
            
End Sub


Public Sub subForceMKDir(ByVal sPath As String)
    Dim var As Variant, v As Variant
    Dim sPth As String
    
    var = Split(sPath, "\")
    
    On Error Resume Next
    
    For Each v In var
        sPth = sPth & v
        VBA.MkDir sPth
        sPth = sPth & "\"
    Next v

End Sub

the code will save to "Image" folder on where your db is.
 
Last edited:
Hi arnelgp,
Thanks for taking the time to respond. I am not actually trying to extract and save the images stored in the MSysResource table.
I am trying to save an inbuilt MS Access image into that table so I can use it as a shared image to be able to swap the picture of a button at runtime.
I was trying the method Joseph P mentioned.

Josef P. said:
You can also change the embedded image (in the form) from embedded to shared, then it will be stored in MSysResources.


I created a button, set the picture type to embedded and selected the down arrow.
1.png


Then according to Josef P, If I change the Picture Type to Shared it will place a copy into MSysResources which it appears to do however it appears to be incomplete. See my images above.

Thanks anyway.
Any other suggestions
 
for "built-in" image on access, that will work. however if the image is from another pc/laptop then not possible.
 
But that's the problem. It is not working for a built in image. I am selecting a built in image after selecting emdedded as the picture type.
 

Users who are viewing this thread

Back
Top Bottom