Question : Using a Button To Insert Object Into Access 2007 Form

Hello,

I have a form which has a bound image field which stores OLE objects (specifically PDF documents) in a MySQL database backend.  When you use this field in the full version of Access 2007 you can right click and insert a document into the table.

However, in Access 2007 RunTime this menu is disabled.  I have seen information on how to create a custom menu which will give the same functionality, albeit with a significant amount of work, but I wish to use a button to insert the object into that field instead of the menu.  Regrettably I have been unable to locate any code or information which makes this process possible.  

What I need is for a user to click the button, have a dialog box pop up (hopefully the same one that full Access 2007 uses when you right click and "Insert Object") for the user to select the file, take that file and add it to the bound object field in the database, thus storing the document for later retrieval as is possible in full Access 2007.

Is this possible and if so, does anyone have a suggestion for a resource which I can use to design and build this function?  

Answer : Using a Button To Insert Object Into Access 2007 Form

The default dialog has many options. If you only want to import PDF files, you need only two steps: identify the file, and run the "embed" action. Specifically, if your control is called bofDocument, then:

    bofDocument.SourceDoc = Input("Please enter file name")
    bofDocument.Action = acOLECreateEmbed

You can of course replace the simple input box by a file browser. The code below implements the basic functionality you want (without error handling).

(°v°)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Private Sub cmdLoadFile_Click()
    
    With FileDialog(msoFileDialogFilePicker)
        If .Show Then
            bofDocument.SourceDoc = .SelectedItems(1)
            bofDocument.Action = acOLECreateEmbed
        End If
    End With
    
End Sub
Random Solutions  
 
programming4us programming4us