Ms SQL SQL VBA查询错误号3075

时间:2017-01-30 05:21:53

标签: access-vba

在我的Access应用程序中,我尝试使用新值连接现有字段值,并且我在VBA中编写了如下代码,我收到错误3075"语法错误缺少运算符"

sUser = UserNameWindows
'    MsgBox sUser
    currenttime = Format(Now(), "dd/mm/yyyy hh:mm:ss")
SqlQuery = "UPDATE tbl_AllRequests " & _
" SET [Status]= 'Archived' " & _
", [History] = [History] & CHR(13) & CHR(10) & 'Archived on' " & currenttime & " ' by ' & '" + sUser + "' " & _
" WHERE [ID] in (" & selectedIDs & ")"
'" SET [History] = concat([History], 'Archived on " & currenttime & " by '" & sUser & "'&')'&" & _
'data=concat(data, 'a')
'SqlQuery = "UPDATE tbl_AllRequests SET Status = 'Archived' WHERE ID in (17, 11)"
Debug.Print "this is new one " & SqlQuery
DoCmd.RunSQL SqlQuery, True 

我在下面的代码行中收到错误。

", [History] = [History] & CHR(13) & CHR(10) & 'Archived on' " & currenttime & " ' by ' & '" + sUser + "' " & _

如果我在' Archived on'之后删除了代码。它有效。

由于

1 个答案:

答案 0 :(得分:0)

首先纠正这个:

currenttime = Format(Now(), "dd/mm/yyyy hh:nn:ss")

然后,在固定文本周围只使用单引号:

", [History] = ([History] + CHR(13) + CHR(10)) & 'Archived on '" & currenttime & "' by '" & sUser & "" & _

此外,首先将现在格式化为字符串表达式,然后通过将其包装在octothorpes(#..#)中将其转换为日期值是没有意义的,当与字符串连接时,它将是再次铸造成一个字符串。