Access开发平台--通用附件管理/删除附件功能代码-杜小杰
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access开发平台


Access开发平台--通用附件管理/删除附件功能代码

发表时间:2016/3/21 12:30:01 评论(4) 浏览(10230)  评论 | 加入收藏 | 复制
   
摘 要:如下图在删除按钮中要实现连同附件一起删除,要在删除事件里加Kill函数
正 文:

 

Public Sub btnDelete_Click()
    On Error GoTo ErrorHandler
    Dim strMsg As String
    Dim strPath As String
    Dim strSQL As String
    Dim strFile As String
    Dim FSO As Object
    Dim rs As DAO.Recordset
    If Me.sfrList.Form.CurrentRecord < 1 Then
        Exit Sub
    End If

    Me.sfrList.SetFocus
    RunCommand acCmdSelectRecord

    strMsg = "确定要连同相应附件一起删除?"
    If MsgBoxEx(strMsg, vbQuestion + vbOKCancel) = vbCancel Then
        Exit Sub
    End If

    strPath = GetParameter("Attachment Path", dbText, "", , , True)
    If Len(Nz(strPath)) = 0 Then strPath = CurrentProject.Path & "\Attachments\"
    If Left(strPath, 2) = ".\" Then strPath = CurrentProject.Path & Mid(strPath, 2)
    If Right(strPath, 1) <> "\" Then strPath = strPath & "\"

    strSQL = "Select * FROM Sys_Attachments Where DataID='" & Me.sfrList![客户ID] & "'"
    Set rs = CurrentDb.OpenRecordset(strSQL)
    Do Until rs.EOF

        strFile = strPath & "\" & rs!AttachmentName
        Debug.Print strFile
        If Dir(strFile) <> "" Then
            Set FSO = CreateObject("Scripting.FileSystemObject")
            If FSO.FileExists(strFile) = True Then   '检测是否存在文件有则删除
                Kill strFile   '删除文件
            End If
            Set FSO = Nothing
        End If
        rs.MoveNext

    Loop
    DAORunSQL "delete * FROM Sys_Attachments Where DataID='" & Me.sfrList![客户ID] & "'"
    rs.Close
    Set rs = Nothing

    DAORunSQL "Delete FROM [客户信息表] Where [客户ID]=" & Nz(Me.sfrList![客户ID], 0)
    Me.RefreshDataList
    Me.btnDelete.SetFocus

ExitHere:
    Exit Sub

ErrorHandler:
    RDPErrorHandler Me.Name & ": Sub btnDelete_Click()"
    Resume ExitHere
End Sub

 


Access软件网交流QQ群(群号:198465573)
 
 相关文章
【access源码示例】上传图片或附件到指定文件夹或共享文件夹的通...  【金宇  2012/6/1】
快速开发平台--通用附件管理/上传下载/添加图片附件的示例  【风行  2014/10/11】
快速开发平台--通用附件解释  【小英  2015/1/27】
Access开发平台--通用附件管理 个性化路径实现方法示例  【杜超  2016/2/22】
快速开发平台--最新平台通用附件管理如何上传附件或图片到服务器共享...  【杜超  2016/2/28】
常见问答
技术分类
相关资源
文章搜索
关于作者

杜小杰

文章分类

文章存档

友情链接