类模块代码如下:
Option Explicit '定义按钮对象和onclick 触发内容 Private WithEvents m_Closebtn As Access.CommandButton Const fEvents As String = "[Event Procedure]" '定义触发方式(access需要有此才能触发click动作,否则无效,也不会报错) 'Public Sub InitCls(frm As Access.Form, btn As Access.CommandButton) Public Sub InitCls(btn As Access.CommandButton) 'Set m_form = frm Set m_Closebtn = btn m_Closebtn.OnClick = fEvents End Sub ’定义出发后的事件内容 Private Sub m_Closebtn_Click() MsgBox "" End Sub
窗体代码如下:
'需要在过程前面定义对象 Private mycmd As clsFrm '窗体加载后,实例化对象 Private Sub Form_Load() Set mycmd = New clsFrm mycmd.InitCls btncloseme End Sub '推出后,释放对象 Private Sub Form_Unload(Cancel As Integer) Set m_Frm = Nothing End Sub
标签:Access,Set,End,Sub,对象,Private,access,使用,Closebtn From: https://www.cnblogs.com/huazhonglou/p/17893858.html