SQL查询....更新表与多个标准与每个单一字段值..喜欢...直到....循环...下一个
问题描述:
我有一个multipleValue字段,其中包含多个指定像...博士,护士,ANM,文员等。SQL查询....更新表与多个标准与每个单一字段值..喜欢...直到....循环...下一个
我想更新一个表,其中指定符合每个指定。我的密码正在追踪,但只有第一个指定才能成功。如何更新所有指定使用代码,如.... DO直到....循环....下一步....在SQL查询
Private Sub PostAssigned_AfterUpdate()
Dim strCriteria As String
Dim varItem As Variant
Dim intCounter As Integer
Dim strClear, strUpdate As String
For Each varItem In Me![PostAssigned].Value
strCriteria = strCriteria & varItem & ","
Next
strClear = "UPDATE MasterGeneralData SET MasterGeneralData.DA_ID = 0 WHERE (((MasterGeneralData.DA_ID)= " & Me.DAAAID & "));"
DoCmd.RunSQL (strClear)
strUpdate = "UPDATE MasterGeneralData SET MasterGeneralData.DA_ID = " & Me.DAAAID & " WHERE (((MasterGeneralData.Emp_Design)= '" & Left$([strCriteria], InStr([strCriteria], ",") - 1) & "'));"
DoCmd.RunSQL (strUpdate)
MsgBox "Dealing Assistant details Updated successfully "
End Sub
答
是的......我知道了......工作良好.. 我的代码是。
Private Sub PostAssigned_AfterUpdate()
Dim strCriteria As String
Dim varItem As Variant
Dim intCounter As Integer
Dim strClear, strUpdate As String
Dim LArray() As String
For Each varItem In Me![PostAssigned].Value
strCriteria = strCriteria & varItem & ","
Next
LArray = Split(strCriteria, ",")
DoCmd.SetWarnings False
strClear = "UPDATE MasterGeneralData SET MasterGeneralData.DA_ID = 0 WHERE (((MasterGeneralData.DA_ID)= " & Me.DAAAID & "));"
DoCmd.RunSQL (strClear)
For i = LBound(LArray) To UBound(LArray)
strUpdate = "UPDATE MasterGeneralData SET MasterGeneralData.DA_ID = " & Me.DAAAID & " WHERE (((MasterGeneralData.Emp_Design)= '" & LArray(i) & "'));"
DoCmd.RunSQL (strUpdate)
Next i
DoCmd.SetWarnings True
MsgBox "Dealing Assistant details Updated successfully "
End Sub
你的问题不清楚。请提供样本数据和样本预期结果。 – Viki888
我有一个名为tabMain,DAID和名称字段的表... DAID的数据类型是数字,名称是字符串。我也有一个窗体frmUpdateDAID其中两个字段..第一.... DAID是数字和第二PostAssigned是多值字段有很多名称...我的问题是,当我更新PostAssigned字段在窗体后选择多个指定然后应更新表的DAID字段与表格DAID字段的值,其中表格的名称等于在名为PostAssigned的表单中选择的每个指定。 – user2245124