删除访问表单附件控件上的附件的另一种编程方法是什么?

问题描述

我的访问表单有一个附件控件,我想让用户能够用他们驱动器中的另一个副本覆盖一个记录的文件。

这是我的代码片段:

Dim cdb As DAO.Database,rstMain As DAO.Recordset,rstAttach As DAO.Recordset2
Dim fldAttach As DAO.Field2

' *Snip*

Set rstAttach = rstMain(strAttachFielD).Value

rstAttach.AddNew
Set fldAttach = rstAttach.Fields("FileData")

   '----------------------------------------------
   '  Here goes "blnFileExists" code that determines whether 
   '  "Myfile.txt" is already in the attachment
   '----------------------------------------------

   If blnFileExists Then
       ' *** Delete "MyFile.txt" from the Attachment
   End If

  fldAttach.LoadFromFile "MyFile.txt"

SO 上的另一位海报问basically the same question here。答案包括:

Private Sub DeleteCurrentAttachment()

    Dim Records     As DAO.Recordset
    Dim Attachments As DAO.Recordset2

    Set Records = Me.RecordsetClone
    Records.Bookmark = Me.Bookmark

    Set Attachments = Records!YourAttachmentFieldName.Value
    While Not Attachments.EOF
        Attachments.Delete
        Attachments.MoveNext
    Wend
    Attachments.Close

End Sub

我的问题是我不确定如何将该答案应用到我的代码中。不会Attachments.Delete删除所有附件,而不仅仅是一个吗?

老实说,我所知道的关于 VBA 中的附件控件和多值字段的大部分内容都来自此处的 SO。从谷歌搜索中,我学到的主要内容是我应该使用超链接。 (我的客户想要这两种选择,所以我必须完成这项工作。)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)