在Access 2010中运行追加查询时出现“表已存在”错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Access 2010中运行追加查询时出现“表已存在”错误相关的知识,希望对你有一定的参考价值。

我的访问数据库中出现了一个奇怪的错误。

错误:

表'[在此处插入表名]'已存在。您创建或重命名了一个表,然后尝试保存它。在Microsoft访问可以保存表之前,另一个用户使用相同的名称创建或重命名。

当RPA团队运行Access宏时,就会发生这种情况,这只是一个按顺序运行的查询列表。

在追加查询期间出现错误,该查询从一个表中获取记录并将它们添加到另一个作为工作环境核心的表中。

这只发生在RPA团队。当我从我的工作站运行相同的宏时,它运行完美。当另外两个被授权的人运行宏时,它运行完美。我不能复制它。在我在谷歌或这里度过的时间里,在这种情况下我也找不到任何对此错误的引用。我很难过。我可能只是输入错误的关键字搜索,但我不知道下一步该怎么做。

提前致谢。

编辑:这是违规追加查询的SQL。这很难看,但这是我必须要与之合作:)

INSERT INTO [New ZSPWAR Prime] (Payer, AI, Bill_doc, 
            Sqwak, Site, Plnt, Billing_Dt, ProfitCntr, Customer, 
            Equipment, Issued_Material, Material_Description, SLoc, 
            Serial_No, ItCC, Mtrl_Grp, Manuf_No, Manuf_Name, RTN, 
            Warranty, PPC, SVO_No, Ref_No, Notification_Subject, 
            AC_C, Corrective_Action, SB_Data, AC_R, Corr_Action_R, 
            SaleDebCre, Sales_Ord, SO_Date, SU, Returned_Material, 
            Returned_SNR, [Reason for Rejection], SLCo, Canel_Doc, 
            Can_Doc_Dt, Tail, ItCa, Sold_to, Sold_to_Name, 
            Customer_PO_No, [User], Comp_Date, OB_Del_NO, OB_Del_DT,
            Ret_Delv, Rt_SO_It, Ret_Date, Ret_EQUI, Ret_Note, 
            NoteCR_DT, NoteCM_DT, Ret_Note_DESC, WACD, 
            Wty_Prog_Code_Desc, PO_NO, PO_DT, PO_PI, VR_Amount, 
            INV_PT_DT, ZZ07, Freight_Amt, [ME23N PO_Owner], VDCD, 
            Ven_Den_Code_Desc, DISP, [Disp code Descr], PRI, HVNE, 
            [Approve By], [MM Vendor Number], [Sourcing Vendor Number],
            [Sourcing Vendor Name], [Vendor Contract], [FFF Class],
            [Ref Contract], [Company Code], [BUSAC TYPE], 
            [Warr Typ], [Aircraft Material], [Aircraft Serial Number],
            [Aircraft Program], [GL Date], [Obj Type], [ID Number],
            [MD04 Purchasing Group], [MD04 PurG Name], [RO Number], 
            [RO Creation Date], [RO Contact Name], [RO Vendor Code], 
            [RO Vendor Name], [ODC Amount], [Issue_New/Rotable], 
            Issue_Core, [Recovery_New/Rotable], Recovery_Core, 
            Labor_Hours, Rate, Labor_Cost, Mtrl_Qty_Billed, 
            Mtrl_ea_Cost, Mtrl_ttl_Cost, Total_Cost, MAUC_STD, 
            Core_cost, Cat_Price, Discount, [% Discount], 
            [ODC Freight], [Repair Cost], [Material Burden], 
            [% Material Burden], [Rotable Depreciation], [% Core Dep],
            [Net Spend], Margin, Item_Cost, [Total Material Burden],
            [Total Rotables Dep], SVO_Direct_Labor, SVO_Labor_OH) 
SELECT [New ZSPWAR Merge].Payer, [New ZSPWAR Merge].AI, 
       [New ZSPWAR Merge].Bill_doc, [New ZSPWAR Merge].Sqwak, 
       [New ZSPWAR Merge].Site, [New ZSPWAR Merge].Plnt, 
       [New ZSPWAR Merge].Billing_Dt, [New ZSPWAR Merge].ProfitCntr,
       [New ZSPWAR Merge].Customer, [New ZSPWAR Merge].Equipment,
       [New ZSPWAR Merge].Issued_Material, [New ZSPWAR Merge].Material_Description,
       [New ZSPWAR Merge].SLoc, [New ZSPWAR Merge].Serial_No, [New ZSPWAR Merge].ItCC,
       [New ZSPWAR Merge].Mtrl_Grp, [New ZSPWAR Merge].Manuf_No, [New ZSPWAR Merge].Manuf_Name,
       [New ZSPWAR Merge].RTN, [New ZSPWAR Merge].Warranty, [New ZSPWAR Merge].PPC,
       [New ZSPWAR Merge].SVO_No, [New ZSPWAR Merge].Ref_No, [New ZSPWAR Merge].Notification_Subject,
       [New ZSPWAR Merge].AC_C, [New ZSPWAR Merge].Corrective_Action,
       [New ZSPWAR Merge].SB_Data, [New ZSPWAR Merge].AC_R, 
       [New ZSPWAR Merge].Corr_Action_R, [New ZSPWAR Merge].SaleDebCre,
       [New ZSPWAR Merge].Sales_Ord, [New ZSPWAR Merge].SO_Date,
       [New ZSPWAR Merge].SU, [New ZSPWAR Merge].Returned_Material,
       [New ZSPWAR Merge].Returned_SNR, [New ZSPWAR Merge].[Reason for Rejection],
       [New ZSPWAR Merge].SLCo, [New ZSPWAR Merge].Canel_Doc, 
       [New ZSPWAR Merge].Can_Doc_Dt, [New ZSPWAR Merge].Tail, 
       [New ZSPWAR Merge].ItCa, [New ZSPWAR Merge].Sold_to, 
       [New ZSPWAR Merge].Sold_to_Name, [New ZSPWAR Merge].Customer_PO_No,
       [New ZSPWAR Merge].User, [New ZSPWAR Merge].Comp_Date, 
       [New ZSPWAR Merge].OB_Del_NO, [New ZSPWAR Merge].OB_Del_DT,
       [New ZSPWAR Merge].Ret_Delv, [New ZSPWAR Merge].Rt_SO_It,
       [New ZSPWAR Merge].Ret_Date, [New ZSPWAR Merge].Ret_EQUI,
       [New ZSPWAR Merge].Ret_Note, [New ZSPWAR Merge].NoteCR_DT,
       [New ZSPWAR Merge].NoteCM_DT, [New ZSPWAR Merge].Ret_Note_DESC,
       [New ZSPWAR Merge].WACD, [New ZSPWAR Merge].Wty_Prog_Code_Desc,
       [New ZSPWAR Merge].PO_NO, [New ZSPWAR Merge].PO_DT, 
       [New ZSPWAR Merge].PO_PI, [New ZSPWAR Merge].VR_Amount, 
       [New ZSPWAR Merge].INV_PT_DT, [New ZSPWAR Merge].ZZ07, 
       [New ZSPWAR Merge].Freight_Amt, [New ZSPWAR Merge].[ME23N PO_Owner],
       [New ZSPWAR Merge].VDCD, [New ZSPWAR Merge].Ven_Den_Code_Desc,
       [New ZSPWAR Merge].DISP, [New ZSPWAR Merge].[Disp code Descr],
       [New ZSPWAR Merge].PRI, [New ZSPWAR Merge].HVNE, [New ZSPWAR Merge].[Approve By],
       [New ZSPWAR Merge].[MM Vendor Number], [New ZSPWAR Merge].[Sourcing Vendor Number], 
       [New ZSPWAR Merge].[Sourcing Vendor Name], [New ZSPWAR Merge].[Vendor Contract], [New ZSPWAR Merge].[FFF Class],
       [New ZSPWAR Merge].[Ref Contract], [New ZSPWAR Merge].[Company Code],
       [New ZSPWAR Merge].[BUSAC TYPE], [New ZSPWAR Merge].[Warr Typ],
       [New ZSPWAR Merge].[Aircraft Material], [New ZSPWAR Merge].[Aircraft Serial Number], 
       [New ZSPWAR Merge].[Aircraft Program], [New ZSPWAR Merge].[GL Date],
       [New ZSPWAR Merge].[Obj Type], [New ZSPWAR Merge].[ID Number],
       [New ZSPWAR Merge].[MD04 Purchasing Group], 
       [New ZSPWAR Merge].[MD04 PurG Name], [New ZSPWAR Merge].[RO Number],
       [New ZSPWAR Merge].[RO Creation Date], [New ZSPWAR Merge].[RO Contact Name], [New ZSPWAR Merge].[RO Vendor Code], 
       [New ZSPWAR Merge].[RO Vendor Name], [New ZSPWAR Merge].[ODC Amount],
       [New ZSPWAR Merge].[Issue_New/Rotable], [New ZSPWAR Merge].Issue_Core,
       [New ZSPWAR Merge].[Recovery_New/Rotable], [New ZSPWAR Merge].Recovery_Core,
       [New ZSPWAR Merge].Labor_Hours, [New ZSPWAR Merge].Rate, [New ZSPWAR Merge].Labor_Cost, 
       [New ZSPWAR Merge].Mtrl_Qty_Billed, [New ZSPWAR Merge].Mtrl_ea_Cost,
       [New ZSPWAR Merge].Mtrl_ttl_Cost, [New ZSPWAR Merge].Total_Cost,
       [New ZSPWAR Merge].MAUC_STD, [New ZSPWAR Merge].Core_cost,
       [New ZSPWAR Merge].Cat_Price, [New ZSPWAR Merge].Discount,
       [New ZSPWAR Merge].[% Discount], [New ZSPWAR Merge].[ODC Freight],
       [New ZSPWAR Merge].[Repair Cost], [New ZSPWAR Merge].[Material Burden],
       [New ZSPWAR Merge].[% Material Burden], [New ZSPWAR Merge].[Rotable Depreciation], 
       [New ZSPWAR Merge].[% Core Dep], [New ZSPWAR Merge].[Net Spend],
       [New ZSPWAR Merge].Margin, [New ZSPWAR Merge].Item_Cost, 
       [New ZSPWAR Merge].[Total Material Burden], [New ZSPWAR Merge].[Total Rotables Dep],
       [New ZSPWAR Merge].SVO_Direct_Labor, [New ZSPWAR Merge].SVO_Labor_OH
FROM   [New ZSPWAR Merge]
WHERE  ( ( ( [New ZSPWAR Merge].Bill_doc ) NOT LIKE "1*" )
         AND ( ( [New ZSPWAR Merge].ItCC ) LIKE "ZCOM" )
         AND ( ( [New ZSPWAR Merge].ItCa ) NOT LIKE "ZRN*" )
       )
        OR ( ( ( [New ZSPWAR Merge].Bill_doc ) NOT LIKE "1*"
             )
             AND ( ( [New ZSPWAR Merge].ItCC ) LIKE "ZCOM" )
             AND ( ( [New ZSPWAR Merge].ItCa ) NOT LIKE "I*"
                 ) ); 

道歉,代码片段功能似乎今天不喜欢我。

答案

如果这是RPA解决方案,我可以假设您创建了一个工作流程,其中创建了一个表格,然后将数据插入其中吗?

如果这样,在使用表后删除表时可能会丢失一个步骤。或者您需要在尝试创建表之前检查表是否存在。

你可以试试这个

Public Function ifTableExists(tblName As String) As Boolean

    If DCount("[Name]", "MSysObjects", "[Name] = '" & tblName & "'") = 1 Then

        ifTableExists = True

    End If

End Function

以上是关于在Access 2010中运行追加查询时出现“表已存在”错误的主要内容,如果未能解决你的问题,请参考以下文章

从 Excel VBA 运行工作参数化 Access SQL 查询 (INSERT INTO) 时出现“需要对象”错误

为啥在 Access 中使用 UNION ALL 时出现 ODBC 连接失败错误?

创建大型 Access 报告时出现内存问题

在 Postgres (Redshift) 中使用两个选择列运行 MAX 聚合查询时出现问题

将 MySQL 数据导入 Access 2010 时出现问题

在连接上更新时出现MS Access语法错误