Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access VBA多字段更新查询_Ms Access_Vba - Fatal编程技术网

Ms access VBA多字段更新查询

Ms access VBA多字段更新查询,ms-access,vba,Ms Access,Vba,我一直在试图修复这段代码,但不知道为什么参数太少:1个错误 strSQL=“更新TBLPProduct” strSQL=strSQL&“设置[Verified_By]=”&Me.txtCurrentUser&“&”、[Verified_Date]=#“&Me.txtAuto_Date&“#”&”、[Status]=“Verified” strSQL=strSQL&“其中[状态]=”未验证“&”和[验证]=-1” 在VBA中将变量附加到查询的语法方面,我仍然有问题。该查询在Access中的myU

我一直在试图修复这段代码,但不知道为什么参数太少:1个错误

strSQL=“更新TBLPProduct”
strSQL=strSQL&“设置[Verified_By]=”&Me.txtCurrentUser&“&”、[Verified_Date]=#“&Me.txtAuto_Date&“#”&”、[Status]=“Verified”
strSQL=strSQL&“其中[状态]=”未验证“&”和[验证]=-1”
在VBA中将变量附加到查询的语法方面,我仍然有问题。该查询在Access中的my
UPDATE
语句中工作

这是我在Access查询中使用的内容:

更新tblProduct SET Verified\u By=forms!FRM认证产品!txtcurrentuser,已验证\日期=表单!FRM认证产品!txtAuto_日期,状态=“已验证”
其中verify=-1和Status=“未验证”;

如果
tblProduct.Verified By
字段是文本数据类型,则问题在于
更新
提供了一个不带引号的文本值。当Access看到未加引号的文本值时,它会假定该值必须是您尚未提供值的参数

在这种情况下,您可以修改代码以包含所需的引号,或者切换到参数查询,而不必担心引号

Dim db作为DAO.Database
将qdf设置为DAO.QueryDef
作为字符串的Dim strSQL
strSQL=“更新tblProduct”&vbCrLf&_
“设置[Verified_By]=[pCurrentUser]、[Verified_Date]=[pAuto_Date]、[Status]='Verified'”&vbCrLf&_
“其中[状态]='未验证'和[验证]=-1”
调试。打印strSQL'这应该可以:

strSQL = "UPDATE tblProduct "
strSQL = strSQL & "SET [Verified_By] = " & Me.txtCurrentUser & ", [Verified_Date] = #" & Format(Me.txtAuto_Date, "yyyy\/mm\/dd") & "#, [Status] = 'Verified' "
strSQL = strSQL & "WHERE [Status] = 'Not Verified' AND [Verify] = -1"