Extracting the images in Access Image Gallery (1 Viewer)

aref

New member
Local time
Today, 06:57
Joined
Jan 10, 2023
Messages
27
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
 

aref

New member
Local time
Today, 06:57
Joined
Jan 10, 2023
Messages
27
Hi
 

Attachments

  • Gallery.jpg
    Gallery.jpg
    34.2 KB · Views: 94

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:57
Joined
Oct 29, 2018
Messages
21,473
Those images are stored in a system table called MSysResources, so you should be able to get them from there.
 

June7

AWF VIP
Local time
Yesterday, 21:57
Joined
Mar 9, 2014
Messages
5,471
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;
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:57
Joined
Feb 19, 2002
Messages
43,275
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?
 

moke123

AWF VIP
Local time
Today, 01:57
Joined
Jan 11, 2013
Messages
3,920
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.
 

aref

New member
Local time
Today, 06:57
Joined
Jan 10, 2023
Messages
27
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?
 

aref

New member
Local time
Today, 06:57
Joined
Jan 10, 2023
Messages
27
embedded
 

Attachments

  • image_2023-09-16_141857209.png
    image_2023-09-16_141857209.png
    9.1 KB · Views: 58

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:57
Joined
Oct 29, 2018
Messages
21,473
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.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 01:57
Joined
May 21, 2018
Messages
8,529
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
 

Josef P.

Well-known member
Local time
Today, 07:57
Joined
Feb 2, 2023
Messages
826
You can also change the embedded image (in the form) from embedded to shared, then it will be stored in MSysResources.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:57
Joined
Feb 19, 2002
Messages
43,275
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.?
 

seemick

New member
Local time
Today, 15:57
Joined
Mar 11, 2024
Messages
12
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:57
Joined
May 7, 2009
Messages
19,243
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:

seemick

New member
Local time
Today, 15:57
Joined
Mar 11, 2024
Messages
12
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:57
Joined
May 7, 2009
Messages
19,243
for "built-in" image on access, that will work. however if the image is from another pc/laptop then not possible.
 

seemick

New member
Local time
Today, 15:57
Joined
Mar 11, 2024
Messages
12
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

Top Bottom