Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export an Embedded OLE Object From Access 97 Table 1

Status
Not open for further replies.

iainmc

Programmer
Dec 2, 2002
53
0
0
GB
Hi,

I have an Access 97 table containing 3000 records or so each with and embedded Word Document in one of the fields. I am trying to essentially download each of these files out of the table to my C: drive as a Word doc but am struggling. I want to do this in a VBA module.

Can anyone point me in the direction of the command i need to use in VBA?

Cheers
 
Here's the word from Microsoft:

"Microsoft Access packages OLE objects in a wrapper before it embeds them in a table, which is why you can't assign the contents of an OLE object field directly to a Word object variable in ADO or Visual Basic. The OLE object storage definition in Microsoft Access is not documented, so there is no easy way to isolate a Word document from its binary header."

ref:
Alas.
 
Thanks for that.

Looks like it's open each doc and File, Save As.. then.
 
iainmc,
Here is a thought, it works on my machine (Win XP, Office 2k).

I created a form that was bound to a table containing a field that contained Word documents (data type: OLE object). I dragged this field onto the form to create a new Bound Object Frame ([tt]Par1[/tt]) and when I preview the form I could see the word doc.

Then I created a button ([tt]Command1[/tt]) with the following code:
Code:
Private Sub Command1_Click()
Dim bobj
Set bobj = Me.Par1
bobj.SaveAs "C:\Test.doc"
Set bobj = Nothing
End Sub

When clicked the Word document appeared in the C drive, yeah! You could massage the code so your form automatically cycles through all the records in the table and saves the documents (instead of the button click I choose to use).

I should note that this particular database does contain reference to Microsoft Word X.X Object Library, I don't know if that will make a difference when calling [tt]SaveAs()[/tt] and it's too late for me to do a whole lot of testing.

Hope this helps,
CMP

(GMT-07:00) Mountain Time (US & Canada)
 
That looks like the sort of thing i've been after, i did try using the SaveAs method(as a guess) but wasn't sure what arguments it needed.

I'll give that a go.

Thanks
 
CautionMP, Thanks for you help on the SaveAs - it works a treat!

There is one teeny tiny problem arising - as i'm looping through a lot of records a WINWORD.EXE process opens up in task manager for each one. This is causing my DB to freeze around the 1500 record mark - do you know how to kill a proccess after i have run the SaveAs method?

I am setting my obj variable to Nothing but that doesn't seem to affect the background process.

Cheers
 
You may try this:
bobj.SaveAs "C:\Test.doc"
[!]bob.Application.Quit[/!]
Set bobj = Nothing

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks, but unfortunately that just closed down my Access Db and not the Objects application (the WINWORD.EXE procees)

Here is what i have

Private Sub CbDownload_Click()

Dim obj As Object
Dim Path As String

On Error GoTo ErrorHandler

Path = InputBox("Enter path for file downloads - ", "File Download Path")

DoCmd.Hourglass (True)
DoCmd.GoToRecord , , acFirst

Do Until Me.CurrentRecord = NewRecord

Set obj = Me!Object

If Not IsNull(Me!Object) Then
obj.SaveAs Path & "\File.doc"
End If

obj.Application.Quit

Set obj = Nothing

DoCmd.GoToRecord , , acNext

Loop
DoCmd.Hourglass (False)

MsgBox ("Download Complete")

ErrorHandler:
Resume Next
End Sub
 
Perhaps this instead ?
If Not IsNull(Me!Object) Then
obj.SaveAs Path & "\File.doc"
[!]obj.Close[/!]
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for that.

Do you know how, in VBA, i can find out what my object is i.e Microsoft Word Doc or XL Spreadsheet. Everything i have found says to use the the OLEClass to SET this but i only want to read it and i can't get the OLEClass to return a value to a variable for embedded objects?

Any ideas?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top