Sometimes it helps to think of Access forms as the class modules they are, and to treat them in a more "object-oriented" manner (i.e., by working with user-defined properties and methods).
================================================== ========
Code behind Sub Form - FormB:
Defines properties and methods that can be called from the Main Form - FormA
Option Compare Database
' Module level data member variable.
Dim m_Test As String
' Public methods.
Public Sub TestSubProcedure(strInitialize As String)
MsgBox "This is the initial string"
End Sub
Public Sub TestSubProcedure2()
MsgBox m_Test
End Sub
' Public property.
Public Property Get TestPropertyProcudure() As String
TestProperty = m_Test
End Property
Public Property Let TestPropertyProcudure(TestValue As String)
m_Test = TestValue
End Property
================================================== ========
================================================== ========
Code behind Main Form - FormA:
Calls properties and methods in the Sub Form - FormB
Private Sub cmdExecuteSubFormProc_Click()
' Call your public routine in the standard module here...
' Call public method in sub form passing in argument. Displays
' MessageBox - "This is the initial string"
Me("FormB").Form.TestSubProcedure ("This is the initial string.")
' Initialize a module level data member variable in the sub form
' using a property procedure.
Me("FormB").Form.TestPropertyProcudure = "This is initialized string."
' Call public method in sub form that processes the initialized data
' member variable. Displays MessageBox - "This is initialized string."
Me("FormB").Form.TestSubProcedure2
End Sub
================================================== ========
Be sure your sub form procedures are defined as PUBLIC.
Just as an aside, a new instance of an Access form can always be instantialted and used with the following syntax:
Dim frm As Form
Set frm = New Form_FormB
' initialize user-defined property
frm.AProperty = aValue
' call user-defined method
frm.AMethod
Should look real familiar to the Visual Studio crowd.
|