name of subform

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?
 
A

Allen Browne

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.
 
M

Marshall Barton

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
 
D

Dirk Goldgar

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.
 

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

Top