KeyDown 事件仅在我将箭头插入字段时运行,而不是在我跳入或在字段中输入键时运行

KeyDown Event Runs Only When I Arrow Into a Field, Not when I Tab into or Enter Key Into the Field

我进行了搜索,但找不到有关此行为的任何帮助。 (我在 Access 2010 中工作,但数据库采用 Access 2000 文件格式。)我在数据表视图中使用表单。如果按下向下箭头键,我编写了下面的代码来从上面的记录中复制库存位置。如果我使用向下箭头键从一个记录垂直向下移动到下一个记录,代码工作正常,但如果我使用 Tab 或 Enter 键从一个字段移动到下一个字段,则代码工作正常。

Private Sub InventoryLocation_KeyDown(KeyCode As Integer, Shift As Integer)
    ' Variables are defined as Public at head of module.
    If KeyCode = vbKeyDown Then
        If Me.CurrentRecord = intPreviousRecordNumber + 1 Then
            If IsNull(Me.InventoryLocation.Value) Then
                Me.InventoryLocation.Value = varPreviousInventoryLocation
                DoCmd.CancelEvent
            End If
        End If
    End If
End Sub

正在根据此处的先前记录填充变量:

Private Sub InventoryLocation_LostFocus()
    ' Variables are defined as Public at head of module.
    varPreviousInventoryLocation = Me.InventoryLocation.Value
    intPreviousRecordNumber = Me.CurrentRecord
End Sub

这是我的第一个 post,但我的大部分答案都是在 whosebug.com 上找到的。任何帮助将不胜感激!谢谢!

我的错误显然是我认为我的变量 intPreviousRecordNumber 可以用于记录中的多个字段。 (我还有一个名为 OverstockLocation 的字段,其 LostFocus 事件设置了 intPreviousRecordNumber 的值。我认为这很好,因为同一记录中的两个字段的值相同。) 显然,Access 反对 InventoryLocation 和 OverstockLocation 试图使用相同的变量。我创建了一个名为 intPreviousRecordNumberOverstock 的新变量,供 OverstockLocation 代码使用,现在两者都按预期工作。