0

我有一个访问表单,它是通过从另一个表单单击按钮打开的。我有一个 Form_Current 事件,它通过 VBA 更新该表单上的几个控件。出于某种原因,这会导致在 Form_Current 完成后触发 BeforeUpdate 事件,即使 MS 帮助文档说在 VBA 中更改控件不会触发此事件。我已设法隔离至少一条将触发此事件的行:

txtEventID = gblEventID

其中 txtEvent ID 是控件的名称,gblEventID 是模块级变量。我无法弄清楚为什么会这样。有任何想法吗?

如果您想查看整个潜艇:

Private Sub Form_Current()

    If (Me.NewRecord = True) Then
        Dim lookupNum As Integer

        txtEventID = gblEventID
        lookupNum = DLookup("Max(Subplot_Num)", "tbl_Subplots", "Event_ID = " & txtEventID.Value) + 1

        If (IsNull(lookupNum)) Then
            txtSubplotNum = "1"
        Else
            txtSubplotNum = lookupNum
        End If

    End If

    If xboPoaching.Value = False Then txtPoachingNotes.Enabled = False

End Sub
4

2 回答 2

0

尽我所能,似乎如果您以编程方式更改控件中的值,则该控件的 Before_Update 事件不会触发,但包含该控件的表单的 Before_Update 事件将触发。MS 文档对此很模糊,但在我的测试中似乎是一致的。

于 2018-11-27T17:22:43.210 回答
0

您可以修改/减少该代码:

Private Sub Form_Current()

    Dim lookupNum As Integer

    If Me.NewRecord = True Then    
        lookupNum = Nz(DMax("Subplot_Num", "tbl_Subplots", "Event_ID = " & gblEventID & ""), 0) + 1
        txtSubplotNum = lookupNum
    End If

    If xboPoaching.Value = False Then 
        txtPoachingNotes.Enabled = False
    End If

End Sub
于 2018-11-19T21:10:33.537 回答