Public Property Get CustomerID() As String CustomerID =
rs("CustomerID") End Property
Public Property Let
CustomerID(NewValue As String) rs("CustomerID") = NewValue End
Property 显然,该属性的Get操作只是简单地返回"CustomerID"字段的值,相应地,Let操作是将"CustomerID"字段设置一个新值。
Public Property Get CustomerID() As String CustomerID =
rs("CustomerID") End Property Public Property Let
CustomerID(NewValue As String) 'If the length of NewValue is greater
than five If Len(NewValue) > 5 Then '... then raise an
error to the program 'using this class Err.Raise
vbObjectError + 1, "CustomerID", _"Customer ID can only be up to five
" & _"characters long!" Else '... otherwise, change the
field value rs("CustomerID") = NewValue End If End
Property 好了,在完成下列步骤之前,我们已经为添加方法花费了不少时间。
在我们的类中添加下列代码:
Public Sub Update() rs.Update End
Sub 该Update方法只是简单地调用记录集对象的Update方法来更新记录。