首页 文章

为什么在更改VBA中的控件时会触发BeforeUpdate事件?

提问于
浏览
0

我有一个Access表单,通过单击另一个表单的按钮打开 . 我有一个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

2 回答

  • 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
    
  • 0

    最好的我可以看出,似乎如果你以编程方式更改控件中的值,该控件的Before_Update事件将不会触发,但是包含该控件的表单的Before_Update事件将会触发 . MS文档对此很朦胧,但在我的测试中似乎是一致的 .

相关问题