Advertisement

02.06.2008 at 02:01PM PST, ID: 23142863
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

How to reference deeply nested forms in VBA

Tags: Microsoft, Access, 2007
I have been pulling [what's left of] my hair out trying to reference a fourth-level-down Sub-Form in a Form using VBA and keep getting road-blocked.  Can anyone give me the correct syntax?  I am specifically trying to change the "AllowEdits" property setting on that lower Form.  (In other cases, I am trying to invoke the Requery action.)  Remember, We're talking four levels down.  I am OK with one Sub-Form down, but it's beyond that where it all jams up.
Start your free trial to view this solution
Question Stats
Zone: Microsoft
Question Asked By: Faulkenator
Solution Provided By: Faulkenator
Participating Experts: 3
Solution Grade: A
Views: 64
Translate:
Loading Advertisement...
02.06.2008 at 02:08PM PST, ID: 20836259

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.06.2008 at 02:09PM PST, ID: 20836263

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.06.2008 at 02:10PM PST, ID: 20836276

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.06.2008 at 02:12PM PST, ID: 20836291

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.07.2008 at 01:40AM PST, ID: 20839398

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.07.2008 at 05:26AM PST, ID: 20840477

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.07.2008 at 05:33AM PST, ID: 20840528

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.07.2008 at 05:45AM PST, ID: 20840617

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.07.2008 at 07:48AM PST, ID: 20841729

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.07.2008 at 08:11AM PST, ID: 20842000

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.07.2008 at 08:52AM PST, ID: 20842443

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.07.2008 at 10:19AM PST, ID: 20843333

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.07.2008 at 10:43AM PST, ID: 20843628

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.07.2008 at 01:13PM PST, ID: 20845266

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.07.2008 at 04:26PM PST, ID: 20846820

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.07.2008 at 04:33PM PST, ID: 20846856

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.07.2008 at 05:12PM PST, ID: 20847020

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.08.2008 at 03:15AM PST, ID: 20849179

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.08.2008 at 03:25AM PST, ID: 20849208

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.08.2008 at 05:57AM PST, ID: 20850057

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.08.2008 at 09:16AM PST, ID: 20852101

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
02.06.2008 at 02:08PM PST, ID: 20836259

Rank: Genius

See this link for the ultimate reference in form/subform ... report/subreport systax

http://www.mvps.org/access/forms/frm0031.htm

Basically - from the Main form:

Me.Subform1.Form.Subform2.Form.Subform3.Form.Subform4.AllowEdits = True ' or false

mx
 
02.06.2008 at 02:09PM PST, ID: 20836263

Rank: Genius

Actually ... one more .Form

Me.Subform1.Form.Subform2.Form.Subform3.Form.Subform4.Form.AllowEdits = True ' or false

mx
 
02.06.2008 at 02:10PM PST, ID: 20836276

Rank: Genius

My post assumes that each subsequent subform is embedded in the subform above, ie in another subform

mx
 
02.06.2008 at 02:12PM PST, ID: 20836291

Rank: Genius

You refer to a subform like this:

Me.NameOfYourSubformCONTROL.Form.NameOfSubformControl2.Form.NameOfSubformControl3.Form.AllowEdits

Note that you MUST get the "NameOfSubformControl" correct ... this is not necessarily the name of the form that you're using, but instead is the name of the Subform CONTROL that you've placed on that form ...

In the attached picture, the FORM that I'm using as a subform is named "frmManagers", but the name of the Subform Control is "sfrmManagers" ... so I'd use Me.sfrmManagers.Form to refer to the FORM that is contained in sfrmManagers.
 
Subform Control
Subform Control
 
 
02.07.2008 at 01:40AM PST, ID: 20839398

Rank: Genius

Faulkenator,

Always remeber that in "most" cases the Expression builder can build these types of "Experssions" for you.
(as the name implies)
;-)

For example:
If you are in design view of your main form, right-click on an empty area of the detail section.
Select "Build Event".
Then Select "Experssion Builder"
On the left hand side you will see the name of your Main form in a "folder style" icon, with a plus "+" sign next to it.
When you double click it, it will open up to the first subform.
You can "drill down" to whatever form you like.
Then in the middle screen you will see all the Objects in/on your selected form.
If you double-click on an object, it will build the "nested" text string for you.

Just FYI

JeffCoachman
 
02.07.2008 at 05:26AM PST, ID: 20840477
Wow, so many responses.  THANKS ALL!
As for:  DatabaseMX:
Me.Subform1.Form.Subform2.Form.Subform3.Form.Subform4.Form.AllowEdits = True ' or false
mx
I have tried that on numerous occasions, and I still get a reference error.
And, yes, I am aware of the issue of the name of the embedded form taking on the caption of the embedded form instead of the name of the embedded form (a source of frustration  for me - I alsways have to go back and copy the SourceObject property to the Name property.  Grrr).

And I have used the expression builder too, and, yet I still get the bad reference error.

In my next post, my friend suggested a great solution that works reall nice (read on):
 
02.07.2008 at 05:33AM PST, ID: 20840528
I define a global Form object for any form that I want to set the AllowEdits property. IE:
Global frmMyDeepForm4 as Form

In the Form_Open event:
Set frmMyDeepForm4 =Me.Form  (In the Close Event:  Set frmMyDeepForm4 = Nothing)

In the top level Form's Button Click event:
frmMyDeepForm4.AllowEdits=True or False

That's it.  Dead simple.  Works like a champ!  I still don't know why all the above syntaxes fail me.

Thanks for the reply.  I'll leave this line open for a day or so and then split up the goodies.

 
02.07.2008 at 05:45AM PST, ID: 20840617
Hmmmm  I wonder if the length of the form name is killing it:

frm_MCGCS_TGUTOE_SubForm_4_Enrollments

(And all the form names above it in the nesting are just as long.)
(The length is greater than 32 - isn't that a "magic numer"?  And, if so, how could Microsoft allow me to get it that long.)

Hmmmmm  Maybe I have tripped over, yet another, bug. . . .Hmmmmm...
 
02.07.2008 at 07:48AM PST, ID: 20841729
By the way,  TGUTOE refers to "The Grand Unified Theory Of Everything"  (Big Form)  :)

And to clarify my earlier post:  The "set frmMyDeepForm4" is set in the SUB FORM's Open/Close event.

The Button CLick event is in the top level Form's button.

 
02.07.2008 at 08:11AM PST, ID: 20842000

Rank: Genius

The max length of an object name is 64 characters ... you're probably using Unicode, which means that you would be limited to 32 characters. This is a documented specification thus it is NOT a bug.

Regardless, you can certainly refer to a 4 deep subform IF you refer to it correctly. To verify this, I just nested 4 subforms and was able to change a label caption on the most deeply nested subform. The only caveat is this: you MUST correctly refer to the Subform controls ... a Subform control contains a form, but to the "parent" form it's just another control. Thus, if you have a Subform control named "sfcNest1" that contains a form named "frmBalance", and you want to get to a control named txtDate, you'd refer to it like this:

Me.sfcNest1.Form.txtDate

Now, if frmBalance contains a subform control named "sfcNest2", you would get a handle on it like this:

Me.sfcNest1.Form.sfcNest2.Form

If the form contained in sfcNest2 contains a Subform control named sfcNest3, do this:

Me.sfcNest1.Form.sfcNest2.Form.sfcNest3.Form

and so on ... in other words, you MUST REFER TO THE SUBFORM CONTROL ... as I mentioned earlier, I just did this with on a form with 4 nested subforms (5 levels deep) and it worked ... if you'd like, I can upload a copy of this to illustrate how to do this correctly.

Finally: The use of Global Variables is generally not a good idea. Global variables can lose their scope if you have an unhandled error (and sometimes even with an On Error Resume Next statement). You would be much, much better off to properly refer to your subform and deal with it directly.
 
02.07.2008 at 08:52AM PST, ID: 20842443

Rank: Genius

The original syntax I posted should have worked - so, it seems something else is going on here ??

mx
 
02.07.2008 at 10:19AM PST, ID: 20843333
Unicode:  An interesting idea, I'll have to see where that is set.  That could be part of it.
Good point about Global Objects.  If I can get the long form to work, I will do that - Thanks.  (However, since the declared object only exists for the life of the -open- form, that should not be too much of a problem, but your point is duely noted.)

As for the  Name.Form.Name2.Form.Name3.Form.AllowEdits syntax:
Strange.  Here is the exact line of test code that fails due to bad reference:

MsgBox Me.frm_MCGCS_TGUTOE_SubForm_3_Issuers.Form.frm_MCGCS_TGUTOE_SubForm_4_ItemsIssued.Form.frm_MCGCS_TGUTOE_SubForm_5_Bins.Form.frm_MCGCS_TGUTOE_SubForm_6_Enrollments.Form.AllowEdits

I've verified these names several times (by copying the Source Object into the Name property).

I verified that the first level works:
MsgBox Me.frm_MCGCS_TGUTOE_SubForm_3_Issuers.Form.AllowEdits

But
MsgBox Me.frm_MCGCS_TGUTOE_SubForm_3_Issuers.Form.frm_MCGCS_TGUTOE_SubForm_4_ItemsIssued.Form.AllowEdits
Does not

(Ignore the fact that I start at "3".  We pulled Forms "1" and "2")
 
02.07.2008 at 10:43AM PST, ID: 20843628
Is there a property Setting for determining the the Unicode property?  When I try to read a text file created by the SaveAsText command, I need to know which method was used to create it.  And, I'll then know what to look out for when using a database.
 
02.07.2008 at 01:13PM PST, ID: 20845266

Rank: Genius

Can you .zip and post your database to www.ee-stuff.com, or perhaps just the forms needed to recreate this?

 
02.07.2008 at 04:26PM PST, ID: 20846820
Sorry, confidentiality would be an issue.  I think the problem is related to the number of charatcers in the name of the forms.  I think Unicode is enabled in the database and that then knocks down the character count to 32.  My form names fall within the 35 to 45 character count. For other, somewhat related reasons, I am trying to find what property setting I can read to determine the unicode setting for the database, or, perhaps for the Access installation on the PC.  That information will "seal the deal"

Back to the forms:  They are fairly simple and straight forward.  The top level is unbound.  The subforms are "daisy chained" just as the data that they are bound to.
 
02.07.2008 at 04:33PM PST, ID: 20846856

Rank: Genius

Are we sure that Unicode applies to object names?

mx
 
02.07.2008 at 05:12PM PST, ID: 20847020

Rank: Genius

<Are we sure that Unicode applies to object names?>

I just named a form with Frm1111 repeated until it hit 64 chars, and Access accepted it so no, this wouldn't acutally apply to object names ... although there is some discussion on the newsgroups regarding this issue when calling forms ...
Assisted Solution
 
02.08.2008 at 03:15AM PST, ID: 20849179
My thought is that Access will accept it due to the statements of an earlier posting in this thread, but that when it comes to referring to it in code, then it gets messed up.  The forms launch no problem, but they don't seem to be able to be referred to in VBA beyond the 32 characters, although I haven't yet fully tested that.  (It is on my agenda for later today).
 
02.08.2008 at 03:25AM PST, ID: 20849208
Forgot to mention:  It is also possible that the cause could be due to one other issue:  Unless the user hits the plus key alongside the record, the subform does not open.  It's possible that my code was referencing a non-existent (at the time) sub form.  When a user hits the plus key, the sub form's Open Event executes.  I'll be testing this today also.
 
02.08.2008 at 05:57AM PST, ID: 20850057
OK.  Here's the definitive answer!  The problem wasn't with the length of the form names, it was that the sub forms had not been opened at the time they were being referenced, so the error appeared.  Once I (aka the user) opened the sub forms by clicking on the plus key to the left of the records, then the references worked!  Gee, shouldn't MS have at least called for the Form Load Event to instantiate the sub form when the master form opens (in Datasheet/SubDatasheet mode)?

I'll hold this question open for a bit more, and then close it and award points to the highest bidder!  :)

I'll also create a new thread for the Unicode questions I still have.
Accepted Solution
 
02.08.2008 at 09:16AM PST, ID: 20852101

Rank: Genius

There is no guarantee as to when a or the order of a form /  subform object(s) are being built in memory.

Once all all objects are 'visible', then original syntax I posted should work.

mx
Assisted Solution
 
 
02.16.2008 at 07:13AM PST, ID: 20909804
How did you accept your own answer as the solution? Wasn't aware you could do that ...

I wasn't aware that we were discussing Datasheet subforms ... in the future, please be very specific about those types of things. Datasheet subforms are never populated until you actually "view" one by clicking on the +, and had you mentioned that early on this would have been solved much more quickly.

 
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628