Results 1 to 3 of 3

Thread: OLE Object in Access Question

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    1

    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:
    1. Dim bytData() As Byte
    2.  
    3. Open "C:\test.rtf" For Binary As #1
    4.                     ReDim bytData(FileLen("C:\test.rtf"))
    5.                        
    6.                     Get #1, , bytData
    7.                     Close #1
    8.                    
    9.     rs_dream.Fields("RTF").AppendChunk bytData
    10.     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...

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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:
    1. Dim bytData() As Byte
    2.   ReDim bytData(rs_dream.Fields("RTF").Size)
    3.   Set bytData = rs_dream.Fields("RTF").GetChunk(0, rs_dream.Fields("RTF").SIZE)
    4.  
    5.   '(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:
    1. Dim stm As New ADODB.Stream
    2.     With stm                          
    3.         .Type = adTypeBinary
    4.         .Open
    5.         .Write rs.Fields(0).Value
    6.     End With
    7.     stm.SaveToFile filename, adSaveCreateOverWrite
    8.     stm.Close

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width