PDA

Click to See Complete Forum and Search --> : Using ADO to pass Word selection as OLE object to Access


Daryl
Nov 16th, 2000, 09:38 AM
Hi,

I am trying to select part of a Word document and save it as an OLE object in Access. I had this going a while back but can't seem to get it now. I used ADO to create a recordset to the database. The field "OLE" in Access is of type "OLE Object". I am not sure of what kind of object I should use within VBA to be passed as "tstOLE" shown below.


With rsTests
.Find Criteria:="Command = '" & tstCommand & "'"
If Not .EOF Then
Else
.AddNew
End If
!Command = tstCommand
!ABRB = tstABRB
!Usage = tstUsage
!Definition = tstDefinition
!Input = tstInput
!Output = tstOutput
!Errors = tstErrors
!TIMEOUT = tstTimeout
!OLE = tstOLE
.Update
.MoveFirst
End With

I've tried declaring "tstOLE" as a Document, Object, Range, and Selection with no luck. Depending on what I declare it as, I define a range within the document, and then tried one of the following:
1) setting tstOLE to Range
2) executing range.select and setting tstOLE to "Selection"
3) executing range.select and storing selection.document

An example is:

Dim tempRange as range
Dim tstOLE as object
...
Set tempRange = ActiveDocument.Range(intStart, intEnd)
tempRange.select
Set tstOLE = Selection


I usually end up getting the "Multiple-step OLE DB operation generated errors." error when it tries to save the object to "OLE". When I had this going the first time, the object showed up in the DB as "Word Document". I could then load the object using an OLE control in my VB program.

I did try using DAO by creating a dbDynaSet recordset. The above code worked when defining tstOLE as a Object and storing "Selection" to it. The problem is that this showed up in the DB as "Long binary file" and when I tried loading the object into my VB program using an OLE control, it gave "Error loading from file" error. I couldn't even right click it in access to edit/open as Word document.

Any help is greatly appreciated.

Daryl