Object name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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
 
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
 
Hi Marshall,

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

Nicodemus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top