472,363 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,363 software developers and data experts.

Subform load order and "Invalid reference to the property Form"

I've recently had a nasty problem with the "Invalid reference to the
property Form" error in subforms - nasty because it doesn't seem to
consistently happen to all forms which contain the same structure and
code. Judging by the forums I've researched, it's not an uncommon
error. I'm happy to say I've found a simple solution.

OVERVIEW: I have a main form (no record source) which contains two
subforms. The subforms are not linked, but there is some code in Sub1
which finds a related record in Sub2. The problem is that the
OnCurrent event in Sub1 runs BEFORE Sub2 has loaded, so the first time
it causes an "Invalid reference to the property Form" error. I trap
for the error, then Sub2 loads, and everything works from this point.

CAUSE: subforms are controls, and they run their events before the
Main forms events. So the sequence of events when I open the Main form
is
Sub1: Open, Load, Activate, Current
Sub2: Open, Load, Activate, Current
Main: Open, Load, Activate, Current
The problem occurs in some forms and not others because of the order I
originally placed the subforms on them!

SOLUTION: Sub2 needs to load before Sub1, so that the code in the Sub1
OnCurrent event can reference it. Unfortunately, there is no load
sequence property for subforms, and the Tab Order property doesn't
affect the sequence of loading. However, you can influence the load
order!
1) remove the subforms from Main and save it. For good measure I also
did a compact and repair
2) add Sub2 to Main and Save it. Being paranoid, I did another compact
and repair
3) add Sub1 to Main and Save it. Now it works and I can get rid of the
error trapping!
Nov 13 '05 #1
1 5262
John, thanks for posting the cause and the solution. It is satisfying to
solve, and anyone who searches groups.google.com will find your solution.

Yes, of course one of the subforms must load before the other, and trying to
refer to the one that has not loaded yet will cause an error. I have a
little disquiet, though at the idea that the load sequence is actually
stable and does not need the error handling. It seems like the kind of thing
that might come back to bite you one day, e.g. if you have to repair a
corruption by importing everything into a new database, or convert to a new
version?

Would it be worthwhile leaving the error-handling for the particular
situation in place?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"John Hunter" <js******@waikato.ac.nz> wrote in message
news:6b**************************@posting.google.c om...
I've recently had a nasty problem with the "Invalid reference to the
property Form" error in subforms - nasty because it doesn't seem to
consistently happen to all forms which contain the same structure and
code. Judging by the forums I've researched, it's not an uncommon
error. I'm happy to say I've found a simple solution.

OVERVIEW: I have a main form (no record source) which contains two
subforms. The subforms are not linked, but there is some code in Sub1
which finds a related record in Sub2. The problem is that the
OnCurrent event in Sub1 runs BEFORE Sub2 has loaded, so the first time
it causes an "Invalid reference to the property Form" error. I trap
for the error, then Sub2 loads, and everything works from this point.

CAUSE: subforms are controls, and they run their events before the
Main forms events. So the sequence of events when I open the Main form
is
Sub1: Open, Load, Activate, Current
Sub2: Open, Load, Activate, Current
Main: Open, Load, Activate, Current
The problem occurs in some forms and not others because of the order I
originally placed the subforms on them!

SOLUTION: Sub2 needs to load before Sub1, so that the code in the Sub1
OnCurrent event can reference it. Unfortunately, there is no load
sequence property for subforms, and the Tab Order property doesn't
affect the sequence of loading. However, you can influence the load
order!
1) remove the subforms from Main and save it. For good measure I also
did a compact and repair
2) add Sub2 to Main and Save it. Being paranoid, I did another compact
and repair
3) add Sub1 to Main and Save it. Now it works and I can get rid of the
error trapping!

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brian Morris | last post by:
I'm new to .NET and just trying a few things out, like emailing. I created a form in Visual Studio .Net to input some information for generating an email and I'm getting the following error when it...
2
by: Good Enchiladas | last post by:
While building on a class library for an object model, I get the above error message. The steps to recreate the problem are as follows: 1. Build a RootLevel.dll containing only this code: ...
6
by: TS | last post by:
Hi, i have a problem validating xml against schema. I used http://apps.gotdotnet.com/xmltools/xsdvalidator/Default.aspx validator and it says it is fine. Can you tell me why this doesn't work? ...
0
by: John Hunter | last post by:
I've recently had a nasty problem with the "Invalid reference to the property Form" error in subforms - nasty because it doesn't seem to consistently happen to all forms which contain the same...
7
by: Dica | last post by:
i've used the sample code from msdn to create an encyption/decryption assembly as found here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT10.asp i'm...
5
by: Mark Ingram | last post by:
Hi, ive written a custom control and i would like to display the "invalid property value" dialog box for certain properties on my form if the user enters a value outside the allowed range (in the...
2
by: Dabbler | last post by:
In my Registrant FormView I have a DropDownList which loads data from a secondary SqlDataSource "sdsOfficeParks". I need the user to select an office park but save the selected value in the...
1
by: Java Guy | last post by:
I'm trying to view a web page. IE tells me there are (Java?) errors on the page. Here they are: Line: 15 Char: 7 Error: Wrong number of arguments or invalid propert assignment Code: 0 URL:...
6
by: KiwiGenie | last post by:
Hi..I am trying to make a search form. I am fairly new to access and could well be looking at it completely wrong. I have an unbound form with textboxes in the header for entering different search...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.