extract ole object in a table to a file

T

thread

Hi all,

does anyone have an example of vba code extracting ole object in a
table to a file?
 
J

Jon Lewis

The code below should help you. Some of it is off the top of my head so
might need tweaking.

It takes an Icon file stored in a table, and extracts it to a temporary file
(the file name and path are obtained using the GetTempPath and
GetTempFileName windows APIs and the temp file is deleted after use using
the DeleteFile API , but you can hard code the filepath/name if you want).

Public Sub LoadCustomIcon
On Error GoTo Err_LoadCustomIcon

Dim IconData() As Byte
Dim lngNo As Long
Dim intNo As Integer
Dim db As DAO.Database
Dim rs As DAO.Recordset

Dim strTempDir As String
Dim strTempFile As String

strTempDir = String(255, Chr$(0))
GetTempPath 255, strTempDir
strTempDir = Left$(strTempDir, InStr(strTempDir, Chr$(0)) - 1)

strTempFile = String(255, 0)

GetTempFileName strTempDir, 0, 0, strTempFile

strTempFile = Left$(strTempFile, InStr(1, strTempFile, Chr$(0)) - 1)

Set db = CurrentDb
Set rs = db.OpenRecordset("YourTable", dbOpenDynaset)
rs.FindFirst "[IDField]='" & ID & "'"

'Not totally sure if this is the right syntax - may need tweaking
lngNo = LenB(rs!OLEField)
ReDim IconData(lngNo - 1)
IconData = rs!OLEField


intNo = FreeFile
On Error Resume Next
Open strTempFile For Binary Access Write Lock Write As intNo
Put #intNo, , IconData()
Close #intNo
On Error GoTo Err_LoadCustomIcon

'**************************
'Do what you want here
'**************************

Call DeleteFile(strTempFile)

Exit_LoadCustomIcon:

Set rs= Nothing
Set db = Nothing
Erase IconData
Exit Function

Err_LoadCustomIcon:
MsgBox Err.Number & ": " & Err.Description, vbExclamation, "Error"
Resume Exit_LoadCustomIcon
End Sub

HTH
 
S

Stephen Lebans

See:
http://www.lebans.com/oletodisk.htm
NEW - Feb 06/2006 ExtractInventoryOLE.zip A2K or higher ONLY! This
version saves the entire contents of a table containing OLE Objects to disk.
Does NOT require the original application that served as the OLE server to
insert the object. Supports all MS Office documents, PDF, All images
inserted by MS Photo Editor, MS Paint, and Paint Shop Pro. Also supports
extraction of PACKAGE class including original Filename. Contains function
to produce a full Inventory of the OLE field including LINKED path and
Filenames. Uses Structured Storage API's to read the actual contents of the
field.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top