Trying to paste a metafile into an Access Jet Recordset with OLE field with VB

Trying to paste a metafile into an Access Jet Recordset with OLE field with VB

Post by Mark Stege » Mon, 25 Mar 2002 01:21:43

Hi All,

This is driving me nuts.  All I want to do is paste a metfile from the
clipboard into an OLE field using a recordset.

I declare the rs

      rsReport.Open "Select * from PackList", conWMS, adOpenKeyset,

Then this line of code returns a "Type Mistmatch" error

    rsReport!Barcode = Clipboard.GetData()

The "Barcode" field is an OLE Object and the data in the clipboard is

Any help would be appreciated.


1. 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

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

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

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.

2. EDA/SQL info

3. moving objects from OLE control to OLE field in jet database

4. truncate problems in PL/SQL

5. VB30: Accessing OLE-field in ACCESS-DB via OLE-VBX

6. HELP!] what's the safe way to export tables(only Data) to file?

7. HELP: VB + Access : Trying to insert an image into Access from VB

8. Comments on EPick by VanArsdale

9. Jet/Access: change field size in VB code???

10. Paste to Pdx Ole field

11. Saving OLE object from VB to Access Database binary field

12. How can I store pictures in access tables (ole-fields) with VB

13. Access OLE Object Field in VB 5.0