Link to home
Start Free TrialLog in
Avatar of MickJackson
MickJacksonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to insert an OLE object using VBA Code

Hi,
I'm having a complete brain fried moment, and I'm fairly sure this shouldn't prove to difficult for anyone here (though I may be wrong). I am trying to add a bit map to a field in a table. It can be done easily enough using the Insert Object from the menu, but I would like the users to browse to a file (this works fine), select the image (again no problem), and then press a confirm button, and a record is created with the image embedded into the appropriate field.

I was trying to create a new record on the form (again no problem) and then setting a bound OLE Object (bound to the correct field name) using the following code..but it just objects saying

Error 2791
Can't link the OLE object or the bound or unbound object frame

Any ideas greatfully received
' Specify Type.
    OLE1.OLETypeAllowed = acOLEEmbedded
    ' Specify source file.
    OLE1.SourceDoc = "C:\Images\ball.bmp"
    ' Create linked object.
    OLE1.Action = acOLECreateLink
    ' Adjust control size.
    OLE1.SizeMode = acOLESizeClip

Open in new window

Avatar of coffeeshop
coffeeshop
Flag of Germany image

You can add pictures as BLOB (binary) or as OLE. For OLE I do this with
frmTemp.OLE1.Class = "jpegfile"
frmTemp.OLE1.Class = "Paint.Picture"
frmTemp.OLE1.OLETypeAllowed = acOLEEmbedded
frmTemp.OLE1.SourceDoc = sFileName
frmTemp.OLE1.Action = acOLECreateEmbed

Open in new window

Sorry: Drop line 1. "jpegfile" is wrong class. There is another solution with sendkeys, using the dialog, but the above seems to me better.
ASKER CERTIFIED SOLUTION
Avatar of puppydogbuddy
puppydogbuddy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MickJackson

ASKER

Lebans was the winner...took me a bit to sort it out then all hell broke loose with another project and have only just come back to this...sorry for the delay

Thanks once again for all the help