当我运行这段代码时,在更新语句中得到运行时错误3144语法错误,不知道我做错了什么。 我有一个列表,我想把它写入数据库中的另一张表(我的主表)。 下面是代码。
Set lst = Me.lstTermEmpl
For Each item In lst.ItemsSelected
CurrentDb.Execute "UPDATE tbl_Staffing SET Term_Heat_Ticket_Num = me.TxtTerm_Heat_Ticket_Num, Inactive_Status_Dt =lst.column(7), Termination_Reason_FK =lst.column(9), WHERE ID = " & _
lst.Column(8) & ";", dbFailOnError
它是重播值的me.TxtTerm_Heat_Ticket_num和Inactive_Status_dt,但不是终止_原因_FK或ID。
也许我在代码中遗漏了什么?
这是我对我的列表的查询。
SELECT Tbl_Term_Employees.Term_ID, Tbl_Term_Employees.Date_of_TermEmplRequest,
Tbl_Term_Employees.NatGen_ID, Tbl_Term_Employees.FirstName,
Tbl_Term_Employees.LastName, IIf([Term_Approval_Status]=0,"Pending SVM Approval","SVM Approved") AS TermApprovalStatus,
Tbl_Termination_Reasons.Termination_Reason,
Tbl_Term_Employees.Inactive_Status_Dt, Tbl_Term_Employees.ID_FK,
Tbl_Term_Employees.Termination_Reason_FK, Tbl_Term_Employees.Team_Fk,
Tbl_Term_Employees.Site_FK
FROM ((Tbl_Term_Employees INNER JOIN Tbl_Termination_Reasons ON Tbl_Term_Employees.Termination_Reason_FK = Tbl_Termination_Reasons.Termination_Reason_ID) INNER JOIN Tbl_Teams ON Tbl_Term_Employees.Team_Fk = Tbl_Teams.Team_ID) INNER JOIN Tbl_Site ON Tbl_Term_Employees.Site_FK = Tbl_Site.Site_ID
WHERE (((Tbl_Term_Employees.Team_Fk)=[forms]![FrmTermEmplList].[cboTeam]) AND ((Tbl_Term_Employees.Site_FK)=[forms]![FrmTermEmplList].[cboSite]) AND ((Tbl_Term_Employees.Term_Approval_Status)=[forms]![FrmTermEmplList].[txtTerm_Approval_Status]));
连接变量输入。表格控件的引用是一个变量。不需要分号";"。删除WHERE前面的逗号。
日期时间类型字段的参数需要#分隔符,文本字段的参数需要省略号。
CurrentDb.Execute "UPDATE tbl_Staffing SET Term_Heat_Ticket_Num = '" & _
Me.TxtTerm_Heat_Ticket_Num & "', Inactive_Status_Dt = #" & lst.column(7, item) & _
"#, Termination_Reason_FK = " & lst.column(9, item) & " WHERE ID = " & lst.Column(8, item), dbFailOnError