in VBA I have a subform which I use on many forms; however I have a bit of code where I only want this code to work on 'one form'; so if I have the subform with a textbox in form 1, form 2 and form 3, I want the after update event to only work for form 2.
What's the best possible way to go about doing this?
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:
Me.Name
).Me.Parent
will throw an error. You would then need to trap that error and ignore it.