Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VB to read a .BMP file into an "OLE Object" Field.

37 views
Skip to first unread message

Martyn Webster

unread,
Aug 22, 2001, 10:55:33 PM8/22/01
to
I've been trying to write VB code (in Access 97) to read small .bmp files
into an "OLE Object" field in a recordset (based directly on a table), so
that it they can be displayed on a form in a bound object control.

Basically, I need to do (with VB code) what the InsertObject action on a
bound OLE Object field does.

I've tried GetObject, LoadPicture and AppendChunk methods in various
combinations, as well as reading the .bmp file in binary mode into a string.
The best I can do so far is to get the data into the field (in "Picture"
class
format), and display it in an Image control by setting it's PictureData
property, in the OnCurrent event.

Does anyone know of a way within Access 97 to do this, or do I need to
get some additional add-on software (e.g. developer's toolkit?)

Regards,
Martyn Webster
Principal Consultant

FIRST STRIKE SOLUTIONS
PO Box 993 Toronto NSW 2283 AUSTRALIA
http://www.firststrike.com.au


Steve Jorgensen

unread,
Aug 23, 2001, 12:18:09 AM8/23/01
to
According to the Access help, it looks like you need the LoadPicture
function. Here's an example copeid from the help entry:

Set Forms!Orders!OLECustomControl.Picture = LoadPicture("Stars.bmp")

Of course, I would never try this without specifying the full path.
Too many could to go wrong otherwise.

Martyn Webster

unread,
Aug 23, 2001, 12:40:42 AM8/23/01
to
Thanks, but I've tried this - it only works for form controls
that already contain an OLE object with a Picture property.

That's the crux of the problem - I can get a picture from a
.bmp file to a Form Control using LoadPicture, or copy an
object from one Field to another using GetChunk/AppendChunk.

What I *can't* do is to read the .bmp file and put it into
an "OLE Object" Field (as an embedded bitmap object).

Regards,
Martyn Webster

FIRST STRIKE SOLUTIONS
PO Box 993 Toronto NSW 2283 AUSTRALIA

Web: http://www.firststrike.com.au


Steve Jorgensen

unread,
Aug 23, 2001, 7:22:30 PM8/23/01
to
Hmm. Try this, then. Under the help index, find OLE Objects ->
Creating and inserting -> SourceDoc Property.

Martyn Webster

unread,
Aug 24, 2001, 2:36:59 AM8/24/01
to
SourceDoc and related methods all apply only to Bound and
Unbound Frame controls (i.e. on forms only). I did however,
manage to use this to do the import, by loading the bitmap
into an unbound frame control (according to the SourceDoc
method Help example), and then saved it to the table using:

rs1!PhotoData = tempFrameCtl.OleData

It's good enough for my purposes this time, so thanks for
your suggestions - they got "near enough to be good
enough".

I'm still interested if anyone can find a way to do this without
needing to use an open form as a workspace.

Larry Linson

unread,
Aug 25, 2001, 10:25:39 PM8/25/01
to
There's example code at http://accdevel.homestead.com that includes a
programmatic method for inserting an OLE object into an OLE field.
However, before you take this approach for large numbers of images,
read the article included in the downloads, and you may decide to try
one of the other methods.

If you download the Access 2000 version, be aware that it is in need
of update: the string variable used to hold the image in the BLOB
method should be changed to a byte array. I have an update, but have
been away from my high-speed connection, so haven't uploaded it. I'll
get it uploaded as soon as I return to my home base.


"Martyn Webster" wrote

0 new messages