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
-
Dim stmFileStream As New ADODB.Stream
-
Dim RS As New ADODB.Recordset
-
...............
-
With stmFileStream
-
.Open
-
.Type = adTypeBinary
-
.LoadFromFile "X:\FileToStoreInTable.ext"
-
RS![oleBLOB] = stmFileStream.Read
-
RS.Update
-
.Close
-
End With
-
.........
-
Set stmFileStream = Nothing
-
Set RS = Nothing
-
- to save BLOB to disk file
-
Dim stmFileStream As New ADODB.Stream
-
Dim RS As New ADODB.Recordset
-
.......
-
With stmFileStream
-
.Open
-
.Type = adTypeBinary
-
.Write RS![oleBLOB]
-
.SaveToFile "X:\FileName.ext"
-
.Close
-
End With
-
.........
-
Set RS = Nothing
-
Set stmFileStream = Nothing
-
Regards,
Fish