[英]UPDATE Query in MS Access using SQL in VBA with declared strings
been a while since I've posted so please forgive any formatting issues.自从我发布以来已经有一段时间了,所以请原谅任何格式问题。 Looking to update a table field with a value from another record in the same field in the same table.
希望使用同一表中同一字段中另一条记录的值更新表字段。
I've declared two strings, and the strDeal string is coming back with the correct values when debugging.我已经声明了两个字符串,调试时 strDeal 字符串返回正确的值。 However when I introduce the string into the sql statement I can't the query to update the field.
但是,当我将字符串引入 sql 语句时,我无法通过查询来更新该字段。 I'm not sure exactly what isn't working correctly, so any help would be appreciated.
我不确定到底是什么工作不正常,所以任何帮助将不胜感激。
The basics are I'm trying to update the Case_Qty
field with a value from the same field in the same table based on the returned value from a subquery.基础知识是我试图根据子查询的返回值,使用同一表中同一字段的值更新
Case_Qty
字段。 Thanks!谢谢!
Dim strDeal As String
Dim strSQL As String
strDeal = DMax("[Deal_No]", "[tblStructuresNoDAworking]", "[Structure_Name] = Forms!frmStructNoDASetup!Structure_Name AND [FG_Ind] = 0 AND [Deal_No] < Forms!frmStructNoDASetup!Deal_No")
strSQL = "UPDATE tblStructuresNoDAworking SET tblStructuresNoDAworking.Case_Qty = (SELECT [Case_Qty] FROM tblStructuresNoDAworking WHERE [Structure_Name] = '" & Me.Structure_Name.Value & "' AND [Deal_No] = '" & strDeal & "') WHERE [Structure_Name] = '" & Me.Structure_Name.Value & "' AND [Deal_No] = '" & Me.Deal_No.Value & "'"
DoCmd.RunSQL (strSQL)
Try this where you concatenate the values from the form:试试这个,你连接表单中的值:
Dim strDeal As String
Dim strSQL As String
strDeal = DMax("[Deal_No]", "[tblStructuresNoDAworking]", "[Structure_Name] = '" & Forms!frmStructNoDASetup!Structure_Name & "' AND [FG_Ind] = 0 AND [Deal_No] < '" & Forms!frmStructNoDASetup!Deal_No & "'")
strSQL = "UPDATE tblStructuresNoDAworking " & _
"SET tblStructuresNoDAworking.Case_Qty = " & _
" (SELECT [Case_Qty] " & _
" FROM tblStructuresNoDAworking " & _
" WHERE [Structure_Name] = '" & Me.Structure_Name.Value & "' AND [Deal_No] = '" & strDeal & "') " & _
"WHERE [Structure_Name] = '" & Me.Structure_Name.Value & "' AND [Deal_No] = '" & Me.Deal_No.Value & "'"
DoCmd.RunSQL strSQL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.