日期:2014-05-16  浏览次数:20733 次

access的类模块?
在vba里定义了一个类模块,初始化及调用都正常
最后 “Set m_窗体 = Nothing ” ‘m_窗体 是类的实例

Private Sub Class_terminate() 这个销毁函数并没有被调用?什么原因啊?

------解决方案--------------------
可以调用

类模块:
'类名称为: clsTest
Private strUserName As String

Public Property Let UserName(ByVal UserName As String)
strUserName = UserName
End Property
Public Property Get UserName() As String
UserName = strUserName
End Property

Private Sub Class_Initialize()
strUserName = "ewang11"
  
End Sub

Private Sub Class_Terminate()
 MsgBox "类已被Terminate"
End Sub


窗体代码

Dim a As New clsTest

Private Sub Command0_Click()
MsgBox a.UserName
End Sub


Private Sub Command1_Click()
 Set a = Nothing '销毁类,会触发Terminate事件
End Sub