Inserting an OLE Object into table from filepath using VBA (1 Viewer)

Cavman

Registered User.
Local time
Today, 19:05
Joined
Oct 25, 2012
Messages
66
I know, I know - OLE Objects create huge databases! In this case I only have several very small images, so no problem with size.

What I'm trying to do however, is insert an OLE Object into a table using VBA/SQL. Currently I have the following code:

Code:
 CurrentDb.Execute ("INSERT INTO tblProjects ( ProjectName, ProjectPath, ProjectIcon, ProjectLogoPath ) " & _
                "VALUES ( '" & IIf(StrComp(UCase(strProjectName), strProjectName, vbBinaryCompare) = 0, strProjectName, StrConv(strProjectName, vbProperCase)) & "','" & strProjectPath & "','" & strProjectIconPath & "','" & strProjectLogoPath & "' );")

ProjectIcon is the OLE Object field in the table and strProjectIconPath holds the path to the image that needs inserting. The above code doesn't error, but the ProjectIcon field in the table reads 'Long Binary Data' rather than 'Bitmap Image' as it should if the code works properly!

Is there a way to successfully insert an image using INSERT INTO or do I need to use another method? I'm still quite new to VBA, so my understanding of how OLE Objects work is a bit sparse!

Thanks,

Simon
 

owensbri

Registered User.
Local time
Today, 11:05
Joined
May 5, 2012
Messages
28
Surprisingly i'm attempting to do almost the exact same thing, and getting the exact same result. It successfully places an object in the table, but it shows as "Long Binary Data".

Hope a solution is forthcoming soon.
 

Cavman

Registered User.
Local time
Today, 19:05
Joined
Oct 25, 2012
Messages
66
Hi,

Doesn't look like there's going to be any solutions forthcoming! To be honest I gave up with the OLE Object route and I'm just using links to the graphics instead. :banghead: This has worked out much better! :)

Where I want an image to appear on a form, I create a picture box, but don't select an image - just hit the cancel button which will leave the frame empty. Add a field to the form which contains the path to the image (I've made mine invisible), and then in the Control Source of the picture box just link to the path field (= txtImagePath).
This is much easier as all that's needed then is to insert the path as a string into the table rather than the actual image as an OLE object. And there are no issues with database size - you just have to ensure that the images are all in an accessible place.

Don't know if that will work with what you're trying to do owensbri?
 

owensbri

Registered User.
Local time
Today, 11:05
Joined
May 5, 2012
Messages
28
I figured out a work around very similar to that, but by storing the images in their own table. I am only using 8 images, and they are all icon size, so the size of the DB getting out of hand isn't an issue. I, too, used a form with an Object Control with no set source and a hidden text field to help select the correct image when the form Loads, using VBA. My issue is performing a requery on the form doesn't dynamically change the image. If I manually reload, the image changes correctly.

This is very frustrating indeed. Thanks for your reply!

- Brian
 

Users who are viewing this thread

Top Bottom