name of subform

  • Thread starter Thread starter Laura
  • Start date Start date
L

Laura

I use the same subform several places on a main form.

From the subforms KeyDown-event I would like to know which
of the subforms on the mainform I am in at the present
moment.

How do I get that information?
 
Good question, and no obvious answer.

As a workaround, you can place an unbound text box on the subform. In the
Load event of the main form, write a value to the text boxes in the subform,
e.g.:
Me.[MySub1].Form![MyTextbox] = 1
Me.[MySub2].Form![MyTextbox] = 2
This gives you a way to identify which instance of the subform you are
working in.
 
Laura said:
I use the same subform several places on a main form.

From the subforms KeyDown-event I would like to know which
of the subforms on the mainform I am in at the present
moment.


Try using:
Parent.ActiveControl.Name
 
Marshall Barton said:
Try using:
Parent.ActiveControl.Name

Here's another one, which you could use even if the subform wasn't
currently the active control on the main form:

Dim ctl As Control

For Each ctl In Me.Parent.Controls
If ctl.ControlType = acSubform Then
If ctl.Form Is Me Then
MsgBox "I'm in the control named " & ctl.Name & "!"
Exit For
End If
End If
Next ctl

But if Laura only needs to know this in the subform's KeyDown event,
your solution is simpler.
 
Back
Top