Log in

View Full Version : Extract embedded images from Access 2007 database



seb1128
02-27-2015, 01:20 PM
Hi, I'm trying to extract an embedded image from an Access database. I found the following code for a User-defined function but I'm unsure of how to use it. Can someone tell me if I can run it within the immediate window in VB and if so, what would be the syntax?

Thanks in advance for any help.

Public Function savePict(pImage As Access.Image)
Dim fname As String 'The name of the file to save the picture to
fname = Environ("Temp") + "\temp.png" 'Destinaiton file path

Dim iFilenum As Double
iFilenum = FreeFile 'The next free file from the file system

Dim pngImage As String 'Stores the image data as a string
pngImage = StrConv(pImage.PictureData, vbUnicode) 'Convert the byte array to string

'Writes the string to the File
Open fname For Binary Access Write As iFilenum
Put #iFilenum, , pngImage
Close #iFilenum
End Function