1

我无法弄清楚缺少的运算符在此行中的位置:

CurrentDb.Execute "INSERT INTO Site_Data" _
 & " ([Pass_Fail], [Tag_Name], [PM_#], [Group_Location_Reference], [Device_Type], [Manufacturer_SN], [Year_Put_Into_Service], [Date_of_Test], [Time_To_Complete], [Description], [Set_Point], [Set_Point_Units], [Fail_Low], [Fail_High], [As_Found], [As_Left], [Date_RFS/Idle], [Comments], [Year], [Month], [Site])" _
 & " SELECT [Pass_Fail], [Tag_Name], [PM_#], [Group_Location_Reference], [Device_Type], [Manufacturer_SN], [Year_Put_Into_Service], [Date_of_Test], [Time_To_Complete], [Description], [Set_Point], [Set_Point_Units], [Fail_Low], [Fail_High], [As_Found], [As_Left], [Date_RFS/Idle], [Comments], " & yrs & " As [Year], " & Mnth & " As [Month], " & SiteName & " As [Site]" _
 & " FROM " & tbl.Name & ";"

编辑

好的,所以变量 yrs = "2013" 有效,但变量mnth = "April"不如site = "Fun_Land"

4

2 回答 2

1

当我试图诊断您的 SQL 语句文本时,我忽略了一些变量。尽管我犯了错误,但我提供的建议仍然是合理的:给自己一个机会,在你面前检查已完成的陈述Execute

Dim strInsert As String
strInsert = "INSERT INTO Site_Data" _
    & " ([Pass_Fail], [Tag_Name], [PM_#], [Group_Location_Reference], [Device_Type], [Manufacturer_SN], [Year_Put_Into_Service], [Date_of_Test], [Time_To_Complete], [Description], [Set_Point], [Set_Point_Units], [Fail_Low], [Fail_High], [As_Found], [As_Left], [Date_RFS/Idle], [Comments], [Year], [Month], [Site])" _
    & " SELECT [Pass_Fail], [Tag_Name], [PM_#], [Group_Location_Reference], [Device_Type], [Manufacturer_SN], [Year_Put_Into_Service], [Date_of_Test], [Time_To_Complete], [Description], [Set_Point], [Set_Point_Units], [Fail_Low], [Fail_High], [As_Found], [As_Left], [Date_RFS/Idle], [Comments], " & yrs & " As [Year], " & Mnth & " As [Month], " & SiteName & " As [Site]" _
    & " FROM " & tbl.Name & ";"
Debug.Print strInsert
CurrentDb.Execute strInsert, dbFailonError

然后,您可以在立即窗口中查看已完成的语句(Ctrl+g将带您到那里)。对于故障排除,您可以复制语句文本,在查询设计器中创建一个新查询,切换到 SQL 视图并将语句文本粘贴到那里。修改查询设计器中的语句以使其正常工作。然后修改您的代码以生成相同的工作语句。

于 2013-10-30T15:33:08.460 回答
0

好的,所以当您将字符串分配给变量时,我已经为任何有同样问题的人解决了我的问题,您需要确保该字符串具有'' example Mnth = "'April'"。

于 2013-10-30T17:06:38.020 回答