Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I reference a custom class from within a Form? 1

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
I have created a class and assign a variable to the class from within my form
Code:
Dim myControl as MyClass
...
Private Sub Form_Load()
Set myControl = New MyClass
End Sub

Private Sub Form_Resize()
myControl.Center
End Sub
Everything works fine until I add a Split Form to my form (Access 2007). On the Form_Resize event Access 2007 doesn't recognize myControl (thinks it is nothing). I can see that it is nothing via debug by examining Me. However, if I examine Forms!MyForm I can see that myControl still exists.

So my question is...what is the syntax for accessing myControl.

I've tried this: Forms!MyForm.myControl.Center ... but it doesn't work
 
I know the solution, but I am not sure why. I tested my guess and it worked. You need to reference the Form object.

Form_MyForm.myControl.Center

I have to ponder this one.
 
To clarify this is only an issue with a split form. No idea why. In your original post if you change the default view back to something other than split view it works.
 
also to make this work you need to make the variable public. Just so you know this has nothing to do with custom classes. The real title is "how to reference a form level variable within a split form". Here is the test

Public myControl As Access.Control

Private Sub Form_Current()
MsgBox Form_form4.myControl.Name
'The below code will break the top works
MsgBox myControl.Name
End Sub

Private Sub Form_Load()
Set myControl = Me.txtBxOne
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top