OLE Object in Access Question
Hello I am working on a program with an Access Database that should store .rtf (RichTextFormat) files.
With this code I can put "test.rtf" Binary in my database where 'rs_dream' is a recordset and 'RTF' is a Datafield of the type OLE Object
VB Code:
Dim bytData() As Byte
Open "C:\test.rtf" For Binary As #1
ReDim bytData(FileLen("C:\test.rtf"))
Get #1, , bytData
Close #1
rs_dream.Fields("RTF").AppendChunk bytData
rs_dream.Update
Now my question is how can I retrieve the .rtf file from my database and save it?
I tried a lot with GetChunk but It didn't work...
Re: OLE Object in Access Question
I havent used those methods myself, but from what I can see from the help/example on GetChunk you should be able to use this:
VB Code:
Dim bytData() As Byte
ReDim bytData(rs_dream.Fields("RTF").Size)
Set bytData = rs_dream.Fields("RTF").GetChunk(0, rs_dream.Fields("RTF").SIZE)
'(use Open again [probably with Put rather than Get) to save to a file)
If not, here's how I've done it in the past:
VB Code:
Dim stm As New ADODB.Stream
With stm
.Type = adTypeBinary
.Open
.Write rs.Fields(0).Value
End With
stm.SaveToFile filename, adSaveCreateOverWrite
stm.Close
Re: OLE Object in Access Question
The OLE Object datatype adds a "header" to the user data stored in the record. I can't remember the exact number of bytes but 98 comes to mind.
You may need to strip off those bytes before re-creating the file on disk. I have never used the ADO Stream object, not sure if it does this automatically.
Google should have the answer.