我有两个自定义类。一种是另一种的财产。我正在尝试从类外部,在Access表单内部设置属性的值。
我在这里不知所措。我试图删除set关键字,结果是它执行了Let,但未定义所述值。如果我尝试将其设置为Nothing,它也会失败。 (我知道狗实际上并不是动物的财产,这只是为了说明。)
'Animal class
Private dog As Dog
Public Property Get oDog() As Dog
Set oDog = dog
End Property '<<<Error happens here.
Public Property Let oDog(myDog As Dog)
Set dog = value
End Property
'If I don't do this, I get an object variable or with block variable not set error.
Public Sub Class_Initialize()
Set dog = New Dog
End Sub
'Dog class
'Dog properties and methods here.
'Form
Private oAnimal As Animal
Set oAnimal = New Animal
Set oAnimal.oDog = New Dog '<<< that fails
我在这里的最终目标是将自定义类的对象属性设置为新对象,但从类外部,从表单。最重要的是,由于某种原因,当我调用Set时,将调用getter而不是“ letter”。我知道自己做错了,只是不知道那是什么。我相信它很明显。
答案 0 :(得分:2)
in让您使用“ myDog”,然后将dog设置为值,尝试将其更改为:
Public Property Let oDog(Value As Dog)
Set dog = Value
End Property