Hi, this is rather an advanced Access programming topic in my opinion.. here goes..
I wrote a class within a form module. The class is specific to the form's controls. The class properties manipulate the form to my desire.
The intention of this class is to use the form as a subform. Think of the form as a custom control i can re-use to my hearts intent.
I'm not a class expert - still learning so bare with me.
Consider the example below:
Inside the FORM Vba module:
Code:
Option Explicit
Private VarSubformObject As Form
Public Property Set SubformObject(obj As Form)
Set VarSubformObject = obj
End Property
Public Property Get SubformObject() As Form
Set SubformObject = VarSubformObject
End Property
Private Sub Textbox1_Click()
SubformObject.Controls("mybutton").Caption = "Hello World"
End sub
Public Sub Test()
SubformObject.Controls("mybutton").Caption = "Hello World"
End sub
From the caller form - contains the object "mylistbox" as a subform control with a source object for the form in subject:
Code:
Option Explicit
Private Sub Form_Load()
Dim ctl As Form
Set ctl = Forms("Main Form").mylistbox.Form
Dim CustomList As Form_DragListboxControl
Set CustomList = New Form_DragListboxControl 'New instance
With CustomList
Set .SubformObject = ctl
.Test
End With
End sub
The form load event in the caller works fine. The object sets and the test method will fire. However, when I physically click in the subform on Textbox1, the click event fires but fails to retain the source object I set in the form_load event. This is simply because after the form_load event terminates, the object is no longer set, correct?
I get an error here:
Inside the Form Module (class):
Code:
Private Sub Textbox1_Click()
SubformObject.Controls("mybutton").Caption = "Hello World"
End sub
I receive object variable or with variable not set.
Is my logic correct that the object is being set to nothing when the caller's form_load event is terminated? If not, then i'm stuck on what to do!
Thanks for any help. Appreciate your time.