How to insert an OLE object using VBA Code

Posted on 2009-04-28
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
    LVL 7

    Expert Comment

    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

    LVL 7

    Expert Comment

    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

    when it comea to ole in an access database, Lebans is the man.

    LVL 1

    Author Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
    In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now