运行时错误3134无法识别问题

时间:2013-12-26 16:12:06

标签: sql vba ms-access-2007

我根据onclick事件

在以下代码上获得运行时错误3134
   strEnt = "INSERT INTO EntList (EntityID, BusinessUnit, EntityName, Position, Location, Client, Dept, DistKey, Salary, Currency, SQ&A, BillRate, Util%, MeritDate, MeritRate) " & _
         "VALUES ('" & Me.EntityID & "', '" & Me.BusinessUnit & "', '" & Me.EntityName & "', '" & Me.Position & "', '" & Me.Location & "', '" & Me.Client & "', '" & Me.Dept & "', '" & Me.DistKey & "', '" & Me.Salary & "', '" & Me.Currency & "', '" & Me.SG_A & "', '" & Me.BillRate & "', '" & Me.Util_ & "', '" & Me.MeritDate & "', '" & Me.Merit_ & "');"
Debug.Print strEnt
CurrentDb.Execute strEnt

debug.print命令将以下代码输出到即时窗口

    INSERT INTO EntList (EntityID, BusinessUnit, EntityName, Position, Location, Client, Dept, DistKey, Salary, Currency, SQ&A, BillRate, Util%, MeritDate, MeritRate) VALUES ('Test10', 'CSS Overhead', 'Walter Tester', 'AutoentryTest', '01002 TELETECH SERVICE CORPORATION', '0001 US LABOR ARB CLIENT', '001 CORPORATE/COMPANY ALLOCATIONS', 'DAE', '250000', 'USD', '0', '300', '1', '', '');

就我所知,一切看起来都应该有效,有人可以帮我看看我错过了吗?

1 个答案:

答案 0 :(得分:1)

您尝试执行的Access SQL:

INSERT INTO EntList (EntityID, BusinessUnit, EntityName, Position, 
                     Location, Client, Dept, DistKey, Salary, Currency, 
                     SQ&A, BillRate, Util%, MeritDate, MeritRate) 
            VALUES ('Test10', 'CSS Overhead', 'Walter Tester', 'AutoentryTest', 
                    '01002 TELETECH SERVICE CORPORATION', '0001 US LABOR ARB CLIENT', 
                    '001 CORPORATE/COMPANY ALLOCATIONS', 'DAE', '250000', 'USD', '0', 
                    '300', '1', '', '');

包含一些无效的列名引用。 SQ&A绝对不是有效的参考,Util%Currency也可能无效。前两个是无效的,因为它们包含对不带引号的名称引用无效的字符。并且Currency 可能无效,因为它可能是一个保留字(我不确定这个)。

解决方法只是用括号([..])引用它们:

INSERT INTO EntList (EntityID, BusinessUnit, EntityName, Position, 
                     Location, Client, Dept, DistKey, Salary, [Currency], 
                     [SQ&A], BillRate, [Util%], MeritDate, MeritRate) 
            VALUES ('Test10', 'CSS Overhead', 'Walter Tester', 'AutoentryTest', 
                    '01002 TELETECH SERVICE CORPORATION', '0001 US LABOR ARB CLIENT', 
                    '001 CORPORATE/COMPANY ALLOCATIONS', 'DAE', '250000', 'USD', '0', 
                    '300', '1', '', '');