在fieldnames中使用变量 - SQL Update语句

时间:2013-12-26 06:22:13

标签: sql ms-access

我是使用Access 2010的新手。我希望执行以下sql update语句,但我的语法有问题。该表称为“预测”,用户将编辑&更新预测的数量。

问题 - 表字段名称为2014_1,2014_2,2014_3 ...以表示存储在数组中的不同月份。我做过研究,我相信动态做到这一点的方法是:

Dim sqlString As String
    sqlString = "UPDATE Forecasts " & _
    " SET Branch_Plant=" & Me.txtBranch_Plant & _
    ", Item_Number_Short='" & Me.txtItem_Number_Short & "'" & _
    ", Description='" & Me.txtDescription & "'" & _
    ", UOM='" & Me.txtUOM & "'" & _
    ", Estimated_Cost=" & Me.txtEstimated_Cost & _
    ", Requesting_Business_Unit='" & Me.txtRequesting_Business_Unit & "'" & _
    ", End_Customer='" & Me.txtEnd_Customer & "'" & _
    ", Project='" & Me.txtProject & "'" & _
    ", Forecasts." & "[" & arrMonthToDisplay(0) & "]" = " & Me.txtProjectedJanVolume " & _
    " WHERE ID =" & Me.txtID.Tag

    MsgBox ("This is the output: " & sqlString)
    CurrentDb.Execute sqlString 

在添加此行之前一切正常

Forecasts." & "[" & arrMonthToDisplay(0) & "]" = " & Me.txtProjectedJanVolume

msgbx输出现在显示:“False”。 sqlString有什么问题?

请帮忙!非常感谢你。

2 个答案:

答案 0 :(得分:1)

", Forecasts.[" & arrMonthToDisplay(0) & "] = " & Me.txtProjectedJanVolume & _
" WHERE ID =" & Me.txtID.Tag

答案 1 :(得分:-1)

您将字符串与字符串进行比较。 改变

", Forecasts." & "[" & arrMonthToDisplay(0) & "]" = " & Me.txtProjectedJanVolume " & 

", Forecasts." & "[" & arrMonthToDisplay(0) & "] = " & " Me.txtProjectedJanVolume " &