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方法来更新记录。