Reputation: 2180
I have a MS Access Form and a Class. The Class has a property: Cost
On the Code for the Form I have:
private clsMyClass as New MyClass
If on the Form I create a button with the code:
MsgBox clsMyClass.Cost ' the value in cost is displayed
I want a Textbox to display this value.
I have tried putting =clsMyClass.Cost
in the Control Source but I get a #?NAME
How can I display the value of my class property in a text box on my form?
Upvotes: 2
Views: 492
Reputation: 97131
Since Access doesn't cooperate with the class property as the text box control source, assign it's value during the form's On Current event.
This worked with Access 2007:
Option Compare Database
Option Explicit
Private clsMyClass As MyClass
Private Sub Form_Current()
Me.txtCost = clsMyClass.Cost
End Sub
Private Sub Form_Open(Cancel As Integer)
Set clsMyClass = New MyClass
End Sub
Upvotes: 3