因此,我尝试按照以下问题作为指导:
这是我单击表单上的控件时遇到的错误:
这是我的界面:
ITransactionRecord
Option Compare Database
Option Explicit
Public Property Get TRANSACTION_DATE() As Date
End Property
这是我的课程:
LedgerRecord
Option Compare Database
Option Explicit
Implements ITransactionRecord
'from interface
Private tTRANSACTION_DATE As Date
Private Property Get ITransactionRecord_TRANSACTION_DATE() As Date
ITransactionRecord_TRANSACTION_DATE = TRANSACTION_DATE
End Property
Public Property Get TRANSACTION_DATE() As Date
TRANSACTION_DATE = tTRANSACTION_DATE
End Property
Public Property Let TRANSACTION_DATE(ByVal newTRANSACTION_DATE As Date)
tTRANSACTION_DATE = CDate(Format((newTRANSACTION_DATE), "m / d / yyyy"))
End Property
TransferRecord
Option Compare Database
Option Explicit
Implements ITransactionRecord
'from interface
Private tTRANSACTION_DATE As Date
Private Property Get ITransactionRecord_TRANSACTION_DATE() As Date
ITransactionRecord_TRANSACTION_DATE = TRANSACTION_DATE
End Property
Public Property Get TRANSACTION_DATE() As Date
TRANSACTION_DATE = tTRANSACTION_DATE
End Property
Public Property Let TRANSACTION_DATE(ByVal newTRANSACTION_DATE As Date)
tTRANSACTION_DATE = CDate(Format((newTRANSACTION_DATE), "m / d / yyyy"))
End Property
我做错了什么?
答案 0 :(得分:3)
Public Property Get TRANSACTION_DATE() As Date End Property
在VBA中,公共接口成员名称中不能包含下划线,因为这样您会得到:
Private Property Get ITransactionRecord_TRANSACTION_DATE() As Date
然后VBA与这两个下划线混淆了,它只是期望一个。在VBA中,实现接口成员(或处理事件源事件)的成员将是名为[Source]_[MemberName]
的私有方法:_
下划线字符在接口成员签名中具有句法含义,应为至少在可能意味着要由其他人实施的任何类中仔细使用。
将属性重命名为 PascalCase TransactionDate
,问题消失了:
Public Property Get TransactionDate() As Date
End Property
Private Property Get ITransactionRecord_TransactionDate() As Date