A subform has a Parent
property. So you can check the Name
property of the subform's Parent
.
Dim strParent As String
strParent = Me.Parent.Name
If strParent = "form 2" Then
' do stuff for form 2
End If
Notes:
- That code is intended for the after update event of a text box on the subform. If the target text box is present on the parent form instead, it's simpler; just check the parent form's name directly (
Me.Name
). - If the subform is opened on its own, ie not as a subform to another form,
Me.Parent
will throw an error. You would then need to trap that error and ignore it.