
Loading Word document from Access OLE field into OLE container control in VB
I am stuck with a problem. I have a table in my Access 97 database. It
has two fields:
ID (Number field and primary)
Data (OLE Object field)
I have one record:
ID Data
1 Microsoft Word 97 Document OLE Object
Fortunately, I do not have to write any data to this table in Visual Basic
5.0 Professional, but I have to read this data into the OLE container
control without the Data control. I have tried the following, but none of
this works:
1. I have tried reading the data into a Byte array, but the OLE container
control does not seem to have the capability of reading an OLE object from
a Byte array (if I try reading the OLE object into a String it seems to not
read everything in the field so the OLE object gets corrupted) without
saving it to a temporary file.
2. I create a temporary file named C:\WINDOWS\TEMP\~SSid.TMP (where id is
the time stamp that GetTempFilename gives it) using the GetTempPath and
GetTempFilename. This file contains the contents of Rs!Data (Rs is a
Recordset with my table open). I save the contents of Rs!Data using the
following:
Dim FNum As Integer, ByteArray() As Byte
FNum = FreeFile
Open "C:\WINDOWS\TEMP\~SSid.TMP" For Binary As #FNum
ByteArray = Rs!Data
Put #FNum, 1, ByteArray
Close #FNum
Then I try this:
FNum = FreeFile
Open "C:\WINDOWS\TEMP\~SSid.TMP" For Binary As #FNum
OLEContainer.ReadFromFile FNum ' Generates an error
Close #FNum
The program crashes because the file is apparently not in the format that
the control can read it in.
3. I try the above, only with an extension of .doc and not .TMP. Same
error.
4. I try the above, with the .TMP extension, only I use
OLEContainer.CreateLink "C:\WINDOWS\TEMP\~SSid.TMP". I see an icon (I have
my control set up to display icon and not contents), but it does not have
the Microsoft Word icon, it has a label of ~SSid.TMP, and when I
double-click it, Object Packager says it can't open it! (Object Packager
isn't supposed to be running, Word is supposed to run).
5. I try the above, with the .doc extension, using OLEContainer.CreateLink
"C:\WINDOWS\TEMP\~SSid.TMP". Before control is returned to code, Microsoft
Word starts and displays the Convert File From dialog box. Apparently Word
doesn't recognize the file as it's own format. When I convert it, I am
returned to the form with the OLE container control. I see an icon with
the Microsoft Word icon, it has a label of Document, and when I
double-click it, MS Word opens the object, and I see a ton of greek and
garbage!
What I'm trying to do is load an OLE object created in Access, saved in an
OLE Object field, and load it into the OLE container control WITHOUT using
the Data control.
I need help desperately, as I have to finish my program by the end of the
week! Any help would be appreciated.
--
James Johnston
My e-mail address on my message tag is junk to
reduce my junk mail. Please use this e-mail
address instead.