表名正确时运行时错误3078

时间:2018-03-01 17:54:22

标签: sql ms-access access-vba

我查了几篇与此相关的文章,没有回答我的问题。

我试图复制tbl_MBR_MiscSteps中有值的所有记录:

CO = Forms!frm_BP10_Tablet_MBR_Process!CO

并将其更改为:

Forms!frm_BP10_Tablet_ViewMBR!TxtSaveAs

我一直在条件表达式中找不到'|1'字段,当我尝试立即窗口时,我收到错误

  

3078:找不到输入表。

我还检查了?currentdb.TableDefs("tbl_MBR_MiscSteps").Name并获得了tbl_MBR_MiscSteps

有人可以告诉我我的代码丢失了吗?

Private Sub Command617_Click()
Dim sSQL As String
q2 = Chr$(34) & Chr$(34)
dq = Chr$(34) 'double quotes

sSQL = "INSERT INTO tbl_MBR_MiscSteps (CO, Step, Tank, RawMaterial, Weight, 
Amount, QuantityWeighed, QuantityDispensed, ScaleID, StartingAmount, " _
& "StartingAmountxBCoatingSolutionNeeded, ContainerTankID, 
NitrogenIsFlowing, Screen, StartTime, StopTime, CompletedByDate, 
CheckedByDate, CommentsBy) SELECT " _
& dq & Replace(Nz([TxtSaveAs]), dq, q2) & dq & "," _
& dq & Replace(Nz([Step]), dq, q2) & dq & "," _
& dq & Replace(Nz([Tank]), dq, q2) & dq & "," _
& dq & Replace(Nz([RawMaterial]), dq, q2) & dq & "," _
& dq & Replace(Nz([Weight]), dq, q2) & dq & "," _
& dq & Replace(Nz([Amount]), dq, q2) & dq & "," _
& dq & Replace(Nz([QuantityWeighed]), dq, q2) & dq & "," _
& dq & Replace(Nz([QuantityDispensed]), dq, q2) & dq & "," _
& dq & Replace(Nz([ScaleID]), dq, q2) & dq & "," _
& dq & Replace(Nz([StartingAmount]), dq, q2) & dq & "," _
& dq & Replace(Nz([StartingAmountxBCoatingSolutionNeeded]), dq, q2) & dq & "," _
& dq & Replace(Nz([ContainerTankID]), dq, q2) & dq & "," _
& dq & Replace(Nz([NitrogenIsFlowing]), dq, q2) & dq & "," _
& dq & Replace(Nz([Screen]), dq, q2) & dq & "," _
& dq & Replace(Nz([StartTime]), dq, q2) & dq & "," _
& dq & Replace(Nz([StopTime]), dq, q2) & dq & "," _
& dq & Replace(Nz([CompletedByDate]), dq, q2) & dq & "," _
& dq & Replace(Nz([CheckedByDate]), dq, q2) & dq & "," _
& dq & Replace(Nz([CommentsBy]), dq, q2) & dq & "," _
& "FROM tbl_MBR_MiscSteps " _
& "WHERE CO = Forms!frm_BP10_Tablet_MBR_Process!CO"
CurrentDb.Execute sSQL, dbFailOnError
End Sub

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情(未经测试完成):

Private Sub Command617_Click()
    Dim sSQL As String
    sSQL = sSQL & "INSERT INTO "
    sSQL = sSQL & "    tbl_MBR_MiscSteps "
    sSQL = sSQL & "    ("
    sSQL = sSQL & "        CO, Step, Tank, RawMaterial, Weight, Amount , QuantityWeighed, QuantityDispensed, "
    sSQL = sSQL & "        ScaleID, StartingAmount, StartingAmountxBCoatingSolutionNeeded, ContainerTankID, "
    sSQL = sSQL & "        NitrogenIsFlowing, Screen, StartTime, StopTime, CompletedByDate, CheckedByDate, CommentsBy"
    sSQL = sSQL & "    ) "
    sSQL = sSQL & "SELECT"
    sSQL = sSQL & "    "" & Replace(Nz([TxtSaveAs]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([Step]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([Tank]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([RawMaterial]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([Weight]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([Amount]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([QuantityWeighed]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([QuantityDispensed]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([ScaleID]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([StartingAmount]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([StartingAmountxBCoatingSolutionNeeded]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([ContainerTankID]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([NitrogenIsFlowing]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([Screen]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([StartTime]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([StopTime]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([CompletedByDate]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([CheckedByDate]), "", """") & "","
    sSQL = sSQL & "    "" & Replace(Nz([CommentsBy]), "", """") & "" "
    sSQL = sSQL & "FROM"
    sSQL = sSQL & "    tbl_MBR_MiscSteps "
    sSQL = sSQL & "WHERE"
    sSQL = sSQL & "    CO = Forms!frm_BP10_Tablet_MBR_Process!CO"
    CurrentDb.Execute sSQL, dbFailOnError
End Sub