M
Mattias Jonsson
I have made a little form that has a few subforms on it. I would like to be
able to load a subform by setting the SourceObject property (don't know at
design time exactly which form will be the subform). If the subform
Form_Load is cancelled, I would like to be able to detect it from the parent
form. Seems like a reasonable thing to do.
Now to what Access (2002, SP 3) does. Here's how to reproduce it
Create frmParent with a subform control on it called TheSubform and a button
called cmdTest. Paste the following code:
**Code start**
Option Compare Database
Option Explicit
Private Sub cmdTest_Click()
Me.TheSubform.SourceObject = "frmChild"
MsgBox Me.TheSubform.Form.TheTestFunction
End Sub
**Code end**
Create frmChild without any controls but with the following code
**Code start**
Option Compare Database
Option Explicit
Private Sub Form_Open(Cancel As Integer)
Cancel = True
End Sub
Public Function TheTestFunction() As String
TheTestFunction = "Doh!"
End Function
**Code end**
Now, make sure both forms are closed. Open the parent form and click the
button.
Hope this will be as intriguing to somebody else as it has been to me.
Behaves the same way in Access 2000, by the way (not tested in earlier
versions). I can work around this problem so I'm not desperate for a
solution but it just seems really weird. Is there perhaps a better way to
load a subform at runtime?
Thanks,
Mattias Jonsson
able to load a subform by setting the SourceObject property (don't know at
design time exactly which form will be the subform). If the subform
Form_Load is cancelled, I would like to be able to detect it from the parent
form. Seems like a reasonable thing to do.
Now to what Access (2002, SP 3) does. Here's how to reproduce it
Create frmParent with a subform control on it called TheSubform and a button
called cmdTest. Paste the following code:
**Code start**
Option Compare Database
Option Explicit
Private Sub cmdTest_Click()
Me.TheSubform.SourceObject = "frmChild"
MsgBox Me.TheSubform.Form.TheTestFunction
End Sub
**Code end**
Create frmChild without any controls but with the following code
**Code start**
Option Compare Database
Option Explicit
Private Sub Form_Open(Cancel As Integer)
Cancel = True
End Sub
Public Function TheTestFunction() As String
TheTestFunction = "Doh!"
End Function
**Code end**
Now, make sure both forms are closed. Open the parent form and click the
button.
Hope this will be as intriguing to somebody else as it has been to me.
Behaves the same way in Access 2000, by the way (not tested in earlier
versions). I can work around this problem so I'm not desperate for a
solution but it just seems really weird. Is there perhaps a better way to
load a subform at runtime?
Thanks,
Mattias Jonsson