With an Access VBA, I am trying to load a file from a directory to the table [table name]
in the field [field name]
which Data Type
is Attachment
.
The problem is that I get the error Invalid field data type
.
The code is the following.
Dim SQL As String
SQL = " SELECT * FROM [table name] WHERE ID = '10'"
Dim VESRecordSet As Recordset
Set VESRecordSet = CurrentDb.OpenRecordset(SQL)
VESRecordSet![field name].LoadFromFile "D:\Documents\file.vsd"
You have made multiple errors:
DAO.RecordSet2
object.LoadFromFile
.Edit
and .Update
when editing and updating a recordsetFinal code:
Dim SQL As String
SQL = " SELECT * FROM [table name] WHERE ID = '10'"
Dim VESRecordSet As DAO.Recordset2
Dim rsAttachments As DAO.Recordset2
Set VESRecordSet = CurrentDb.OpenRecordset(SQL)
VESRecordSet.Edit
Set rsAttachments = VESRecordSet![field name].Value
rsAttachments.AddNew
rsAttachments.Fields("FileData").LoadFromFile "D:\Documents\file.vsd"
rsAttachments.Update
rsAttachments.Close
VESRecordSet.Update
VESRecordSet.Close
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.