Cach Tao Class Trong VBA
Cuong Servenet > 16-08-18, 11:47 AM
Chia se cach tao class nút đóng cho form nhé anh. Bác nào có cách nào nữa thì chia sẻ em biết với nhé
[code]Option Compare Database
Option Explicit
Public Event BeforeClose(Cancel As Integer)
Private WithEvents MyFrm As Access.Form
Private WithEvents CloseBtn As Access.CommandButton
Private name_ As String
Property Let Name(value As String)
name_ = value
End Property
Private Sub Class_Initialize()
name_ = "ketthuc"
End Sub
Private Sub CloseBtn_Click()
Dim Cancel As Integer
RaiseEvent BeforeClose(Cancel)
If Cancel Then
Exit Sub
End If
DoCmd.Close acForm, MyFrm.Name
End Sub
Public Sub Bind(Frm As Access.Form)
Set MyFrm = Frm
Dim ctl As Access.Control
For Each ctl In MyFrm.Controls
Select Case ctl.ControlType
Case acCommandButton
Select Case ctl.Name
Case name_
Set CloseBtn = ctl
CloseBtn.OnClick = "[EVENT PROCEDURE]"
Exit For
End Select
End Select
Next ctl
End Sub