1

此代码将使用活动用户 id (NBK) 更新表 (tbl_DateTracking),并根据两个值CaseID和更新记录OCC_Scenario

问题来了:我们只想将 id 添加到当前正在记录的记录中。问题是所有具有 CaseID/OCC_Scenario 的记录都使用用户 ID 进行更新。换句话说,旧记录正在被更改。

任何人都可以看到要添加到此代码中的内容:仅此当前记录,添加 id ???

If IsNull(DLookup("[NBK]", "Employees", "[Status]=1")) Then
Retval = MsgBox("Login information not found - Please choose your role manually", vbOKOnly, "Login Error")
     Else
log = DLookup("[NBK]", "Employees", "[Status]=1")

SQLnbk = " Update tbl_DateTracking SET NBK = "
SQLnbk = SQLnbk & "'" & log & "' WHERE "
SQLnbk = SQLnbk & "CaseId = '" & CaseId & "' AND OCC_Scenario = '" & OCC_Scenario & "';"
End If
DoCmd.RunSQL SQLnbk
4

1 回答 1

0

It seems that you are updating records in a form. You can refer to controls on the form, for example:

If IsNull(DLookup("[NBK]", "Employees", "[Status]=1")) Then
   Retval = MsgBox( _
      "Login information not found - Please choose your role manually", _
      vbOKOnly, "Login Error")
Else
   log = DLookup("[NBK]", "Employees", "[Status]=1")
   Me.txtNBK=log

    End If

If you are using a query, you will need a unique ID. For example:

SQLnbk = " Update tbl_DateTracking SET NBK = "
SQLnbk = SQLnbk & "'" & log & "' WHERE "
SQLnbk = SQLnbk & "UniqueID = " & Me.UniqueID

<...>
CurrentDB.Execute SQLnbk, dbFailOnError
于 2012-09-11T18:41:30.267 回答