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!

Nested tab controls and subforms - How to reference 1

Status
Not open for further replies.

Eutychus

Programmer
Nov 14, 2007
61
US
I have not found the answer to my problem in other threads and wonder if it is even possible to do what I want to do. I have a Main Form, with a Tab Control with several tabs on it. On one of those tabs, I have a subform. On that subform, I have another Tab Control. On one of the tabs on that Tab Control I have another subform. I want to set the AllowEdits property on the last subform when the Main Form is opened. I will do that in an Event Procedure in the OnOpen event of the Main Form. I do not know how to create the reference to the last subform. Microsoft's article 209099 did not do it for me nor has my own experimenting been successful. So here's the hierarchy:
Main Form > Tab Control 1 > Subform 1 > Tab Control 2 > Subform 2. The record source for the Subform 2 is a different table from the Main Form. Can anyone help me with a reference that works or is this impossible?
Thanks much!
 
How are ya Eutychus . . .

When referencing subforms on Tab Controls ... [green]the trick[/green] [thumbsup2] [blue]is to look at it as if the Tab Controls don't exist![/blue] This leaves you with:
[tt][purple] MainForm with embedded subForm1
embedded subform1 with embedded subForm2
[/purple][/tt]

The code in the mainforms [blue]On Load[/blue] event (a better event to use), would look like:
Code:
[blue]   [subForm1].form![subForm2].form.AllowEdits = False[/blue]

[blue]your thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks TheAceMan1! Your response helped! I got it working. Following your advice, here's the format that worked:
Forms![frmMain].Form!subform1.Form!subform2.Form.AllowEdits = False


 
Eutychus . . .

Alough it works (and I could leave it as is! ... surprised an error wasn't raised), I don't wan't you carry a bad programming habit! [surprise]

Be aware ... [blue].Form[/blue] is for subForms only! Meaning that the reference (as far as proper syntax is concerned) should be"
Code:
[blue]Forms![frmMain].subform1.Form!subform2.Form.AllowEdits = False[/blue]
See the difference! [surprise] ... or the programming practice you need to adhere to!

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
TheAceMan1,
Thanks for the additional tip. Actually, I've tried it three ways now:
1. Forms![frmMain].Form!subform1.Form!subform2.Form.AllowEdits = False
2. Forms![frmMain].subform1.Form!subform2.Form.AllowEdits = False (Your code)
3. Me.subform1.Form!subform2.Form.AllowEdits = False

All three ways work for me. I plan to use #3, since the Me. reference is a bit more efficient. I'm glad to know #1 is not really good programming practice. I'm not sure why the .Form after the "frmMain" is not good practice. I'm not doubting you--just wondering what I don't understand.
Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top