访问VBA:无效的字段数据类型

时间:2018-01-02 11:18:04

标签: access-vba

使用Access VBA,我尝试将目录中的文件加载到[table name] [field name] Data Type字段Attachment中的表Invalid field data type

问题是我收到错误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"

enter image description here

代码如下。

.arrow-down {
  width: 100%;
  margin: 0 auto;
  text-align: center;
}

.arrow-down::after {
  content: "";
  width: 40px;
  height: 40px;
  position: absolute;
  margin-top: 49%;
  margin-left: 48%;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  border-right: 4px solid rgb(255, 0, 0);
  border-bottom: 4px solid rgb(0, 255, 0);
  -webkit-transform: rotate(45deg);
  animation: 3s arrow infinite ease;
}

1 个答案:

答案 0 :(得分:0)

您犯了多个错误:

  1. 要使用附件,您应该使用DAO.RecordSet2对象
  2. 您必须先打开包含文件数据的子记录集,然后才能使用.LoadFromFile
  3. 编辑和更新记录集时,您应该使用.Edit.Update
  4. 最终代码:

    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