Access 2016 set control events at runtime

不打扰是莪最后的温柔 提交于 2019-12-12 06:03:29

问题


Is there a way to add an event handler for a control at runtime?

Regard this code (in the form I have only 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

With that code, the two handlers are called.
If I remove the handler TextBox1_MouseDown, the tb_MouseDown is not fired.

来源:https://stackoverflow.com/questions/43219351/access-2016-set-control-events-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!