MS Access - Add OLE objects to table with VBA

余生长醉 提交于 2021-01-28 00:40:18

问题


I am using Access 2016 and Office 2016.

I have a form named "frmFiles". On that form I have a bound object frame named "FileOLE" and a button named "Command2". I have a table named "tblFiles" with 2 fields in it. One named "ID" (AutoNumber/Primary key) and a second named "File" (OLE Object).

My form's RecordSource is linked to my table, and my bound object frame control's ControlSource to my table's "File" field.

My goal is to append the same Excel worksheet to my table each time I click the "Command2" button.

Here is the code I have so far:

Private Sub Command2_Click()
    Me.FileOLE.Class = "Excel.Sheet"
    Me.FileOLE.OLETypeAllowed = acOLEEmbedded
    Me.FileOLE.SourceDoc = <My worksheet's full path>
    Me.FileOLE.Action = acOLECreateEmbed
    Me.FileOLE.SizeMode = acOLESizeZoom
End Sub

This works only for the first click. It will add the worksheet to the empty table. After that, all subsequent clicks will fail to append the file to the table.

What I am missing if that is even possible to accomplish?

Thanks.

来源:https://stackoverflow.com/questions/60494121/ms-access-add-ole-objects-to-table-with-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!