Access交流中心

北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |

[5分]附件删除代码 出错提示标准表达式中的数据类型不匹配 要怎么改了

李连平  发表于:2016-12-30 11:56:37  
复制

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![员工编号] & "'"
    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![员工编号] & "'"
    rs.Close
    Set rs = Nothing
    DAORunSQL "Delete FROM [客户信息表] Where [员工编号]=" & Nz(Me.sfrList![员工编号], 0)
    Me.RefreshDataList
    Me.btnDelete.SetFocus
ExitHere:
    Exit Sub
ErrorHandler:
    RDPErrorHandler Me.Name & ": Sub btnDelete_Click()"
    Resume ExitHere
End Sub

 

Top
MDZZ 发表于:2016-12-30 13:04:47
'" & Me.sfrList![员工编号] & "'"员工编号是文本型?

李连平 发表于:2016-12-30 19:12:06
不会写代码    要怎么改了     

MDZZ 发表于:2017-01-04 10:13:25

用差错方法 找到到底是哪句sql 出问题了 检查员工编号的类型 

文本型表示法 '" & 变量 & "'
日期型表示法 #" & 变量 & "#
数值型(布尔型)表示法 " & 变量



总记录:3篇  页次:1/1 9 1 :