Solved Exporting images from MSysResources (1 Viewer)

KitaYama

Well-known member
Local time
Today, 13:04
Joined
Jan 6, 2022
Messages
1,962
I'm looking at a database with more than 5000 images in MSysResources table.
Before deleting them all, I wanted to have a look at what they really are. Opening them one by one, doesn't seem to be elegant.

Is there any peace of code (or any other way) to export these images to a folder?

I appreciate any kind of advice.
 
The images are stored as attachments. To access them you need to know that they are stored as a recordset in the "Data" Field of MSysRecources. See Work with attachments in DAO.
Code:
Sub ExportAttachmentsFromMSysRessources()
Dim db As DAO.Database
Set db = CurrentDb
Dim mSysResources As DAO.Recordset
Set mSysResources = db.OpenRecordset("MSysResources", dbOpenSnapshot)
Do Until mSysResources.EOF
    Dim attachmentData As DAO.Recordset
    Set attachmentData = mSysResources.Fields("Data").Value
    If Not attachmentData.EOF Then
        Const pathToFolder  As String = "path\To\Folder"
        attachmentData.Fields("FileData").SaveToFile pathToFolder & "\" & mSysResources.Fields("Name").Value & "." & mSysResources.Fields("Extension").Value
    End If
    mSysResources.MoveNext
Loop
End Sub
Just replace "path\To\Folder" with valid path.
 
Last edited:
just create a continuous form based on msysresources
images should appear under the data tab
Not sure if anything other than images are contained in the table but you might need to apply a filter

I used the wizard which produced this
1683823848925.png
 
I'm looking at a database with more than 5000 images in MSysResources table.
Before deleting them all, I wanted to have a look at what they really are. Opening them one by one, doesn't seem to be elegant.

Is there any peace of code (or any other way) to export these images to a folder?

I appreciate any kind of advice.
Simpy refer to img name on MSysResources table
1.) Insert img on the table MSysResources -> for ex. ExcelFile32.png
Data: Attach the image​
Extension: png​
id : autonumber​
Name: ExcelFile32​
Type: img​
2.) in the code refer to the image found with Dloockup()

ex code:

Code:
Private Sub Btn1_Click()
' ?DLookup("[Data]", "[MSysResources]", "[Name] = 'NewOrderBlack'") --> Field Data: NewOrderBlack.png
' ?DLookup("[Name]", "[MSysResources]", "[Name] = 'NewOrderBlack'") --> Field Name: NewOrderBlack
xImg = DLookup("[Name]", "[MSysResources]", "[Name] = 'NewOrderBlack'")
nImg = DLookup("[Name]", "[MSysResources]", "[Name] = 'ExcelFile32'")
mImg = DLookup("[Name]", "[MSysResources]", "[Name] = 'MonitorGrid32B'")

'Controls: ImgBox1, ImgBox2, ImgBox3, Btn2, Btn3
' imgboxes
For x = 1 To 3
    With Forms("Form1").Controls("ImgBox" & x)
        .PictureType = 2
        .SizeMode = acOLESizeClip   'acOLESizeClip or acOLESizeStretch or acOLESizeZoom
        .picture = DLookup("[Name]", "[MSysResources]", "[Name] = 'NewOrderBlack'")
        ' OR .picture = xImg
    End With
Next

'buttons NEED 32x32 img size .SizeMode Don't work!
With Me.Btn2
        .PictureType = 2
        .picture = DLookup("[Name]", "[MSysResources]", "[Name] = 'ExcelFile32'")
        ' OR .picture = nImg
End With
With Me.Btn3
        .PictureType = 2
        .picture = DLookup("[Name]", "[MSysResources]", "[Name] = 'MonitorGrid32B'")
        ' OR .picture = mImg
End With

End Sub
 

Attachments

  • MSysResources tabel.png
    MSysResources tabel.png
    75.2 KB · Views: 26
  • Images on SharedTab.png
    Images on SharedTab.png
    155.5 KB · Views: 24
  • Resullt.png
    Resullt.png
    17.2 KB · Views: 27
Last edited:
Simpy refer to img name on MSysResources table
1.) Insert img on the table MSysResources -> for ex. ExcelFile32.png
Data: Attach the image​
Extension: png​
id : autonumber​
Name: ExcelFile32​
Type: img​
2.) in the code refer to the image found with Dloockup()

ex code:

Code:
Private Sub Btn1_Click()
' ?DLookup("[Data]", "[MSysResources]", "[Name] = 'NewOrderBlack'") --> Field Data: NewOrderBlack.png
' ?DLookup("[Name]", "[MSysResources]", "[Name] = 'NewOrderBlack'") --> Field Name: NewOrderBlack
xImg = DLookup("[Name]", "[MSysResources]", "[Name] = 'NewOrderBlack'")
nImg = DLookup("[Name]", "[MSysResources]", "[Name] = 'ExcelFile32'")
mImg = DLookup("[Name]", "[MSysResources]", "[Name] = 'MonitorGrid32B'")

'Controls: ImgBox1, ImgBox2, ImgBox3, Btn2, Btn3
' imgboxes
For x = 1 To 3
    With Forms("Form1").Controls("ImgBox" & x)
        .PictureType = 2
        .SizeMode = acOLESizeClip   'acOLESizeClip or acOLESizeStretch or acOLESizeZoom
        .picture = DLookup("[Name]", "[MSysResources]", "[Name] = 'NewOrderBlack'")
        ' OR .picture = xImg
    End With
Next

'buttons NEED 32x32 img size .SizeMode Don't work!
With Me.Btn2
        .PictureType = 2
        .picture = DLookup("[Name]", "[MSysResources]", "[Name] = 'ExcelFile32'")
        ' OR .picture = nImg
End With
With Me.Btn3
        .PictureType = 2
        .picture = DLookup("[Name]", "[MSysResources]", "[Name] = 'MonitorGrid32B'")
        ' OR .picture = mImg
End With

End Sub
with a function:
Public Function GetPicture(Num_pic As Integer)
' get picture from MSysResources table
GetPicture = DLookup("[Name]", "[MSysResources]", "[id] = " & Num_pic & "")
End Function

on a form code:
Me.ImgBox3.picture = GetPicture(22) ' the ID number of the image (wastebasket.png)
 

Users who are viewing this thread

Back
Top Bottom