473,394 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 5383
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.