How to insert an OLE object using VBA Code

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

Who is Participating?
puppydogbuddyConnect With a Mentor Commented:
when it comea to ole in an access database, Lebans is the man.

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.
MickJacksonAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.