Connecting Tech Pros Worldwide Forums | Help | Site Map

How to export out the OLE object content to a folder (c:\temp)

chinfk's Avatar
Newbie
 
Join Date: Oct 2007
Posts: 15
#1: Dec 5 '07
Hi Guys,

I have OLE field in the tables, in the datasheet view, it is written there as "packager". Usually, I insert the field content by insert object ways ( insert a PDF ).

How should I export all the files / object to a particular folder in C:\Temp ?

Thanks in advancevd.

FishVal's Avatar
Expert
 
Join Date: Jun 2007
Location: Israel
Posts: 2,584
#2: Dec 12 '07

re: How to export out the OLE object content to a folder (c:\temp)


Hi, chinfk.

It seems that there is no way to do it via code as long as Packager object doesn't support automation.
What do you think about storing the files in BLOBs ? It may be an efficient solution in a case you are storing read-only files.

Regards,
Fish
chinfk's Avatar
Newbie
 
Join Date: Oct 2007
Posts: 15
#3: Dec 13 '07

re: How to export out the OLE object content to a folder (c:\temp)


Hi Brother Fish,

Thanks for your advice, did this feature available in MS access ?
FishVal's Avatar
Expert
 
Join Date: Jun 2007
Location: Israel
Posts: 2,584
#4: Dec 14 '07

re: How to export out the OLE object content to a folder (c:\temp)


Quote:

Originally Posted by chinfk

Hi Brother Fish,

Thanks for your advice, did this feature available in MS access ?

Oh, ye. It is available.

BLOB may be stored in OLE type table field. In table view you will see "Long binary data" in non-empty field. Access does not have native mechanism to save BLOB to table but with some code it could be easily achieved via Recordset object.

There are at least two methods to manipulate BLOB in a table field.
  • using GetChunk / AppendChunk methods available both in DAO and ADO
  • using ADODB.Stream object ("Microsoft Activex Data Objects" version at least 2.5 has to be referenced - open Tools > References, uncheck currently referenced ADO library if its version is lower, check reference to the latest version, e.g. in Access2003 ADO 2.8 is available)

The second method is simpler and faster.

The following examples assumes that ADODB.Recordset is already opened and its cursor is on an appropriate record. Field storing BLOB has name [oleBLOB].
  • to save file contents to a table as BLOB
    Expand|Select|Wrap|Line Numbers
    1. Dim stmFileStream As New ADODB.Stream
    2. Dim RS As New ADODB.Recordset
    3. ............... 
    4. With stmFileStream
    5.     .Open
    6.     .Type = adTypeBinary
    7.     .LoadFromFile "X:\FileToStoreInTable.ext"
    8.     RS![oleBLOB] = stmFileStream.Read
    9.     RS.Update
    10.     .Close
    11. End With
    12. .........
    13. Set stmFileStream = Nothing
    14. Set RS = Nothing
    15.  
  • to save BLOB to disk file
    Expand|Select|Wrap|Line Numbers
    1. Dim stmFileStream As New ADODB.Stream
    2. Dim RS As New ADODB.Recordset
    3. .......
    4. With stmFileStream
    5.      .Open
    6.      .Type = adTypeBinary
    7.      .Write RS![oleBLOB]
    8.      .SaveToFile "X:\FileName.ext"
    9.      .Close
    10. End With
    11. .........
    12. Set RS = Nothing
    13. Set stmFileStream = Nothing
    14.  

Regards,
Fish
Newbie
 
Join Date: Apr 2009
Posts: 1
#5: Apr 4 '09

re: How to export out the OLE object content to a folder (c:\temp)


What did you use to format your source so well?

Thanks, Hans
Reply


Similar Microsoft Access / VBA bytes