Find name of main form

P

Peter Stone

Novice, Access 2003, XP

I want to pass a control name to another application. The control is on a
subform, but I don't know the name of the main form because the subform is in
various mainforms.

E.g. fsubTxt contains txtBox1. How do I find the name of frmMain and then
pass the frmMain!fsubTxt.Form!txtBox1

Thank you
 
J

Jeanette Cunningham

You can get the main form's name by using
Screen.ActiveForm.Name

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
P

Peter Stone

Thank you

Just what I needed.

Can I pass a reference to the control like this?

Screen.ActiveForm.Name!fsubTxt1.Form!txtPub
 
D

Daryl S

Peter -

I haven't needed to try this, but I think you can declare an object variable
and then set the object to be the control you want.

Dim objControl as object
objControl = Screen.ActiveForm.Name!fsubTxt1.Form!txtPub

Then you can pass the object.

Someone else may have done this?
 
J

Jack Leach

Another way would be to store the ActiveForm.Name in a variable and call it
through the Forms collection...

Dim sForm As String
sForm = Screen.ActiveForm.Name
Debug.Print Forms(sForm).Controls(fsubTxt1).Form.Controls(txtPub).Value


--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 

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