[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


How to insert an OLE object using VBA Code

Posted on 2009-04-28
Medium Priority
Last Modified: 2012-05-06
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

Question by:MickJackson
  • 2

Expert Comment

ID: 24250587
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


Expert Comment

ID: 24250611
Sorry: Drop line 1. "jpegfile" is wrong class. There is another solution with sendkeys, using the dialog, but the above seems to me better.
LVL 38

Accepted Solution

puppydogbuddy earned 2000 total points
ID: 24250912
when it comea to ole in an access database, Lebans is the man.


Author Comment

ID: 25289040
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question