在运行时访问2016设置控件事件

时间:2017-04-04 23:21:42

标签: access-vba ms-access-2016

有没有办法在运行时为控件添加事件处理程序?

注意这段代码(我只有TextBox1的形式):

Option Compare Database
Option Explicit

Dim WithEvents tb As Access.TextBox

Private Sub Form_Load()
  set tb = TextBox1
End Sub

Private Sub tb_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Debug.Print "tb_MouseDown"
End Sub

Private Sub TextBox1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Debug.Print "TextBox1_MouseDown"
End Sub

使用该代码,将调用两个处理程序 如果我删除处理程序TextBox1_MouseDown,则不会触发tb_MouseDown。

0 个答案:

没有答案