我正在使用DLookup
Dim FormName As String
Dim OldBBusinessterm As Long
Dim field As Long
Dim NewBusinessTerm As String
Dim NewRecord As DAO.Database
Dim rstUpdate As DAO.Recordset
oldbusinessterm = Me!BusinessTermID.OldValue 'equal 5194 in test
NewBusinessTerm = Me!BusinessTermID.Value ' equal 5195 in test
BusinessTerm = DLookup("[businesstermdesc]", "tblbusinessterm", " [businesstermid] =" & oldbusinessterm)
' here is the issue - [businesstermid] = 5195 - it should be setting the value from Oldbusinessterm but it is populating it from New businessterm
Set NewRecord = CurrentDb
Set rstUpdate = NewRecord.OpenRecordset("TblFieldTermLink")
rstUpdate.AddNew
rstUpdate("GTSBusinessTerm").Value = BusinessTerm
rstUpdate("BusinessTermID").Value = Me!BusinessTermID.Value
rstUpdate.Update
我的问题是它是从我的打开表单中读取businesstermID,而不是使用旧值来执行dlookup。
关于为什么
的任何想法答案 0 :(得分:0)
当您向表TblFieldTermLink
添加新记录时,您正在使用新的BusinessTermID值。如果您想要旧值,则应修改代码以反映:
rstUpdate.AddNew
rstUpdate("GTSBusinessTerm").Value = BusinessTerm 'String Text describing old BusinessTermID
rstUpdate("BusinessTermID").Value = oldbusinessterm 'Long Value of old BusinessTermID
rstUpdate.Update
我还注意到您没有使用您声明的变量来保存旧业务术语ID:
Dim OldBBusinessterm As Long
oldbusinessterm = Me!BusinessTermID.OldValue 'equal 5194 in test
注意两者的拼写。这就是资本化没有遵循的原因。也许您想要更正Dim
声明:
Dim OldBusinessTerm As Long