PMFJI but I believe that you *can* find the parent control of a subform even
when the same form is used as the SourceObject for multiple subform
controls. The trick is to compare hWnd property of the current subform with
the hWnd properties of the main form's subforms. It's not pretty but
consider the following code:
Public Function GetSfrmParentCtlName(pFrmIn As Form) As String
Dim ctl As Control
Dim inti As Integer
Dim fOk As Boolean
Dim strX As String
fOk = False
If IsSubForm(pFrmIn) Then
Do Until inti > pFrmIn.Parent.Controls.Count Or fOk
If pFrmIn.Parent.Controls(inti).ControlType = acSubform Then
If pFrmIn.Parent.Controls(inti).SourceObject = pFrmIn.Name
Then
If pFrmIn.Parent.Controls(inti).Form.hWnd = pFrmIn.hWnd
Then
strX = pFrmIn.Parent.Controls(inti).Name
fOk = True
End If
End If
End If
inti = inti + 1
Loop
'GetSfrmParentCtlName = pFrmIn.Parent.ActiveControl.Name
End If
If fOk Then
GetSfrmParentCtlName = strX
Else
GetSfrmParentCtlName = vbNullString
End If
End Function
Public Function IsSubForm(pFrm As Form) As Boolean
Dim strName As String
On Error Resume Next
strName = pFrm.Parent.Name
IsSubForm = (Err = 0)
End Function
--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Not when a subform wants to get know what subform control it came
from in the parent form!
Try this experiement. Create a main form frmA. Add three subform
controls sf1, sf2, sf3. Put the same subform frmB into each of those
controls. Now write code in frmB's code module, to determine display
Oops! No can do.
This >is< a valid scenario. For example, the subform might be showing
daily bookings. sf1 might be filtered on January, sf2 on February &
so on.
Cheers,
TC