Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reference to sub-subform 1

Status
Not open for further replies.

mahnatz

Programmer
Aug 26, 2007
6
PL
Hi everyone,

short notice than a question.
I have a Main Form (1) with:
- SubForm (2) and
- SubForm (3) that has its own subform (3a) that has also its own(3aa).

Such sophisticated structure was a need to retrieve at once data by end-users (phone-consultants)

So, does anybody have an idea how to refer to subform (3aa) from a level of (2)?
I thought of 'SetFocus' method but I could do it only between 3a & 3aa. I did it just like that:

Sub Button_Click()

me.3aa.SetFocus
RunCommand acCmdRecordsGotoNew

End Sub

In the next step I tried to refer via statement
Forms!1.2.Form!3.Form!3a.Form!3aa.Setfocus

but each of my trial made a bug

Reasuming:
How to refer to the subform from a higher level?

Thanks for any clues,
Bye,
Mahnatz
 
Is form 3 a subform of the main form? If so, try something like this:

[tt]Set frm=Me.3.Form.3a.Form
MsgBox frm("3aa").Form.txtTexbox1[/tt]
 
How are ya mahnatz . . .

Level2 means you want to reference from 3a.
Code:
[blue]   Set frm = [3aa].Form[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Thanks U both Remou & AceMan,

I made a small mistake. I exaggerated with a number of those subs - there is no such as 3aa, sorry.

I have Main Form (1) with two parallel subforms (2) and (3).
(3) has its own subform (3a).

The last one (3a) is the one I need to refer to with a control placed on (2).

The function should of course add a new record on (3a)
I used:

Private Sub Button_Click()
Set frm = 1.3.3aForm
frm.SetFocus
RunCommand acCmdRecordsGoToNew
End Sub

and received a bug: "Object required"
Mahnatz
 
You seem to be short a few forms, if 1 is the main form:

[tt]Set frm = Forms!1.3.Form.3a.Form[/tt]
or
[tt]Set frm = Me.3.Form.3a.Form[/tt]

Have a look here:

With my version of Access 2000, you can run into problems if you go down too many levels, hence my suggestion in the post above.
 
mahnatz . . .

[blue]Remou's[/blue] 1st suggestion [blue]should do the trick[/blue]. In the second [blue]Me[/blue] references 2 . . . NG!

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Oops. That should read:

[tt]Set frm = Me.Parent.3.Form.3a.Form[/tt]

Here are some notes from testing:

Code:
Set frm = Me.Parent.[3].Form.[3a].Form
MsgBox frm("Text0")
Me.Parent.[3].Form.[3a].SetFocus
frm("Text0").SetFocus
MsgBox frm("Text0").Text

 
Thanks You guys,
sorry I haven't respond quicker but I had to xchange my notebook ;)

Remou, Your last sample does work properly - msgbox shows a good reference and display the "Text0" value but after I finaly type:

RunCommand acCmdRecordsGoToNew I receive a bug executing it kind of: "Run-time error '2046': The command or action GoToNewRecord' isn't available now."

similar bug i got executing methode docmd:
DoCmd.GoToRecord acDataForm, "3", acNewRec
"run time error 2489 "the objects '3' isn't open"

i check google for some solutions of this 'last step'
thanks U once again!
Mhtz
 
mahnatz . . .

Try:
Code:
[blue][purple][b]DoCmd[/b][/purple].RunCommand acCmdRecordsGoToNew[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
AceMan,
i can not catch it. Although i finally set focus on the (3a) (msgbox indicates the reference is proper),

DoCmd.RunCommand acCmdRecordsGoToNew

seems to refer to Form(2) because it adds a new record to this form(2).

I tried several times to set (3a) within an 'adding record' metod but still receiving run-time 2046 or 2489 as earlier...

Mhtz
 
mahnatz . . .

Post the current code as you have it!

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Code:
Set frm = Me.Parent.[3].Form.[3a].Form
Me.Parent.[3].Form.[3a].SetFocus
DoCmd.RunCommand acCmdRecordsGoToNew


as well as

Code:
Set frm = Me.Parent.[3].Form.[3a].Form
Me.Parent.[3].Form.[3a].SetFocus
DoCmd.GoToRecord acDataForm, "Przesylka", acNewRec

I am convinced the reference is correct but don't know why following docmd methode doesn't work...

Mhtz
 
Try this:

Code:
Set frm = Me.Parent.[3].Form.[3a].Form
frm("NameOfAControl").SetFocus
frm.Recordset.AddNew
 
Glad you were able to get this sorted out. Referring to forms, subforms, and sub-subforms can get a bit loopy. Keri Hardwick created a series of tables on how to refer to controls on subforms/parent forms, it's available on The Access Web: Forms: Refer to Form and Subform properties and controls.

Hopefully you'll find this useful when you need run across this problem next time.

Cheers,
Larry
 
LarrySteele
The document you mention is, indeed, excellent, however it deals with referring to, at most, two nested subforms: mahnatz has three nested subforms. I have found that in Access 2000, the normal way of referring to subforms breaks down at that level.
 
Remou,

Good point that the document does limit its scope to two levels and would fall short for anyone working with three levels. Still, it's an excellent tool to use if you're working with two levels and wanted to make sure those who read the thread in the future know it's available.

- Larry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top