运行时错误"3073":操作必须使用可更新的查询



我有一些 vba 代码,我正在尝试使用它来导出查询结果,每次我的代码尝试导出时 它抛给我一个错误,Run-time error '3073': Operation must use an updateable query,我不确定为什么。 导出其他表和查询工作正常,即使使用相同的规范也是如此。关于我遇到什么样的问题的任何想法?单步执行可确认它解决了DoCmd.TransferText行上的问题

Public Function exportJobDetailRecs(dateStr As String)
'Docmd.TransferText(acexport,specName,TableName, FileName,HasfieldNames,HTMLTableName)
    Set fso = CreateObject("Scripting.FileSystemObject")
    If Not fso.FileExists(directory + CStr(dateStr + "_OrderStatus_jobdets.txt")) Then
        Set temp = fso.createTextFile(directory + CStr(dateStr + "_OrderStatus_jobdets.txt"))
        temp.Close
    Else
        MsgBox "It looks like you have already run the report (or partially run the report) today. Please Remove all remnants of the text output files and re-run." + vbNewLine + directory + CStr(dateStr + "_OrderStatus_jobdets.txt"), vbOKOnly, "Previously Run exports"
        Exit Function
    End If
    Dim fnameStr As String
    fnameStr = CStr(dateStr + "_OrderStatus_jobdets.txt")
    DoCmd.TransferText acExport, _
                        "JobDetail", _
                        "2_JobDetail", _
                        directory + fnameStr
    exportJobDetailRecs = fnameStr
End Function

我不认为这是查询本身,因为右键单击导出具有相同规范的查询就可以了,但是访问查询生成的SQL在这里

TransferType acExport可能需要是以下 msdn.microsoft.com/en-us/library/office/ff194227.aspx 之一。您的查询看起来像一个选择,所以我认为该错误可能是误报。

最新更新