问题
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