Object name

N

Nicodemus

Hello,

From VBA, inside a Subform, to retrieve :
1) my form's name , I use : Me.Parent.Name
2) my subform's name, I use : Me.Name

But how do I retrieve the object's name containing my subform ?
Thx for any help,
Nicodemus
 
G

Graham Mandeno

Hi Nicodemus

That's an interesting one - I've never had to do that before. However, the
following code should work:

Public Function GetSubformContainer(sbf As Form) As SubForm
Dim ctl As Control
On Error Resume Next
For Each ctl In sbf.Parent.Controls
If ctl.ControlType = acSubform Then
If ctl.Form Is sbf Then
Set GetSubformContainer = ctl
Exit Function
End If
End If
Next ctl
End Function

You can then use:

GetSubformContainer(Me).Name
 
M

Marshall Barton

Nicodemus said:
From VBA, inside a Subform, to retrieve :
1) my form's name , I use : Me.Parent.Name
2) my subform's name, I use : Me.Name

But how do I retrieve the object's name containing my subform ?


This will do that as long as the reference is in the
subform:
Me.Parent.ActiveControl.Name
 
N

Nicodemus

hi Graham,

great code ! It works fine and I will probably use it in other
circumstances. In the current situation, I think I will use the trick Marshal
suggested.
Thank you for your fast answer,
Nicodemus

Graham Mandeno said:
Hi Nicodemus

That's an interesting one - I've never had to do that before. However, the
following code should work:

Public Function GetSubformContainer(sbf As Form) As SubForm
Dim ctl As Control
On Error Resume Next
For Each ctl In sbf.Parent.Controls
If ctl.ControlType = acSubform Then
If ctl.Form Is sbf Then
Set GetSubformContainer = ctl
Exit Function
End If
End If
Next ctl
End Function

You can then use:

GetSubformContainer(Me).Name

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Nicodemus said:
Hello,

From VBA, inside a Subform, to retrieve :
1) my form's name , I use : Me.Parent.Name
2) my subform's name, I use : Me.Name

But how do I retrieve the object's name containing my subform ?
Thx for any help,
Nicodemus
 
N

Nicodemus

Hi Marshall,

that's exactly what I was looking for !
Thank you for your help,

Nicodemus
 
Top