Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Word OLE Automation from VB6


Message #1 by "Kemper, Sheryl" <SKemper@c...> on Fri, 24 Jan 2003 13:19:40 -0800
>From: "Kemper, Sheryl" <SKemper@c...>
>Date: Fri, 24 Jan 2003 13:19:40 -0800
>
>I am writing a VB 6 application to use an OLE container to activate Word in
>its own window.  I want to read in a BLOB (formatted Text) field from the
>database (SQL Server 2000), load it into Word, let the user update it with
>formatting and write it back to the database.  I cannot figure out the OLE
>syntax to get the info from the database.  Does anyone know how to do this?
>Also, any suggestions on reference material?

Aside from possibly not being a very good idea to store Word documents in 
the database...

To save an existing Word document to an OLE field in the database:

Substitute the "c:\WordDocs\MyDoc.doc" with
the name of the file you want to save.
This assumes the existence of the recordset "oRs"
which contains the OLE field "DocField"
'--------------------------
Dim mStream As ADODB.Stream
Set mStream = New Stream
With mStream
  .Type = adTypeBinary
  .Open
  .LoadFromFile "c:\WordDocs\MyDoc.doc"
End With

oRs.Add
oRs("DocField").value = mStream.Read
'-----------------------------------


To work with the Doc file, you need to extract the field containing the
Word document to a (temporary) file.
Let's assume you have a recordset "oRs" which contains the field
"DocField":


'-----------------------------------
Dim sFile As String
     sFile = App.Path & "\temp.doc"

Dim mStream As ADODB.Stream
Set mStream = New Stream
With mStream
   .Type = adTypeBinary
   .Open
   .Write oRs("DocField").Value
   .SaveToFile sFile, adSaveCreateOverWrite
End With
'-----------------------------------

Now, you can work with the temp.doc file under Word

Regards,
-Toby


  Return to Index