Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Unanswered: Invalid reference to the parent property

    I get the error "the expression you entered has an invalid reference to the parent property" whenever I open some of my MSAcess programs which references the parent property.

    I didn't get this error until I tried opening an MSAccess program someone asked me to look at. I searched the web and found that I'm supposed to set the "Break on all errors" (i.e. Tools -> Advanced) to something else. I did this and it worked but I'd like to set it back to "Break on all errors" but when I do, I get the error again. I tried re-installing Office but that didn't work. Does anyone know what might have gotten messed up and how I can fix it so I can set it back to "Break on all errors" without getting the error?

    The wierd thing is that it only happens on some of my MSAccess programs which had no problems and some of them work fine. What's complexing is that the code utilized where the error happens (referencing the parent form) is exactly the same (all references are the same) between the ones which have no problem and the ones which do.
    Last edited by pkstormy; 05-27-07 at 23:41.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  2. #2
    Join Date
    Aug 2006
    Posts
    559
    Maybe the dbs are corrupted? Errors within the file? Hope it's none of mine!?!

  3. #3
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    It was someone else I was helping with a small problem they were having - nothing wierd or unusual about the db - no com/activeX objects. I've compiled, compiled and repaired to no avail. I use the same class modules in 2 different db's and in one it works fine, the other it doesn't and breaks on 1 of the class modules (parent line) but both the class modules are exactly the same and the code which calls them is the same.

    It bugs me that there is no difference in the way the class modules are called but it works in one and not the other. If I make an mde there isn't a problem. If I insert the modules into a new mdb file from one that works, I get the error when I initially run the mdb, but if I open it a second time, it works fine. If I make a change in the code and compact and repair, I get the error. Yet if I close the db and reopen it, it works fine (wierd).

    If I insert the modules into an mdb from one that doesn't work, I get the error no matter how many times I run it. I know it sounds like I need to re-install MSAccess but I've done that three times now (uninstalling and re-installing, restarting, shutting-down, etc.). My visual basic projects works fine with no problems.

    Here's the code where it breaks:

    Private Function GetIsSubform() As Boolean
    ' Is our form currently loaded as a subform?
    ' Check its Parent property to find out.

    Dim strName As String

    On Error Resume Next
    strName = frm.Parent.Name <- breaks on this line and gives the error. Happens in some mdb's and others it doesn't. If I debug, it errors. If I open a 2nd time it works fine.
    GetIsSubform = (Err.Number = 0)
    Err.Clear
    End Function

    All logic tells me there is something different between the mdb's but there really isn't. I would guess that something is corrupt or a reference is missing but nothing seems to be wrong. I've searched and searched the web but can't find anything that would make sense on this.
    Last edited by pkstormy; 05-28-07 at 02:15.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by pkstormy
    I've compiled, compiled and repaired to no avail.
    Do you mean decompiled, compiled and repaired?
    -------------------------------------------------------
    Quote Originally Posted by pkstormy
    I searched the web and found that I'm supposed to set the "Break on all errors" (i.e. Tools -> Advanced) to something else. I did this and it worked but I'd like to set it back to "Break on all errors" but when I do, I get the error again.
    Quote Originally Posted by pkstormy
    Here's the code where it breaks:

    Private Function GetIsSubform() As Boolean
    ' Is our form currently loaded as a subform?
    ' Check its Parent property to find out.

    Dim strName As String

    On Error Resume Next
    strName = frm.Parent.Name <- breaks on this line and gives the error. Happens in some mdb's and others it doesn't. If I debug, it errors. If I open a 2nd time it works fine.
    GetIsSubform = (Err.Number = 0)
    Err.Clear
    End Function
    Paul - isn't the first statement incompatible with the code? "Break on All Errors" is broadly like telling Access to "ignore all error handling". You can't use this option and then run code that intentionally trips errors. Am I missing something?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    You don't want "Break on all errors", because that does exactly what it says, it breaks on all errors, even those you handle in code. When you're in the Tools | Option dialog, hit F1 to read a bit about it:

    "Error Trapping

    Determines how errors are handled in the Visual Basic development environment. Setting this option affects all instances of Visual Basic started after you change the setting.


    * Break on All Errors Any error causes the project to enter break mode, whether or not an error handler is active and whether or not the code is in a class module.
    * Break in Class Module Any unhandled error produced in a class module causes the project to enter break mode at the line of code in the class module which produced the error.
    * Break on Unhandled Errors If an error handler is active, the error is trapped without entering break mode. If there is no active error handler, the error causes the project to enter break mode. An unhandled error in a class module, however, causes the project to enter break mode on the line of code that invoked the offending procedure of the class."

    You probably want "Break on Unhandled Errors.", which will allow your error handling routines to handle the error ("Break in Class Modules" offers possibilities to debub class modules). See also this FMS article, recommending to test/set this at startup http://www.fmsinc.com/free/NewTips/A...ccesstip42.asp.

    Why it seems to trigger sometimes and not other, can indicate that either the form is loaded as a subform the next time (could perhaps be some "sequence of events"/timing issues playing up?), that the app use the SetOption method and change the setting (http://support.microsoft.com/kb/209884), or as suggested, there might be corruption issues.

    If you're not familiar with /decompile, check out these step by step instructions http://www.granite.ab.ca/access/decompile.htm. Though, note that between step 2 and 3, close all instances off Access so that the first compact is in another instance of Access than the one you used to /decompile with (again without running any code at startup).

    If this isn't enough, running the (hidden) methods SaveAsText/LoadFromText of the application object, might work (dumping the object to a text file, and reloading it again)

    application.saveastext acform, "NameOfForm", "c:\NameOfForm.txt"
    application.loadfromtext acform, "NameOfForm", "c:\NameOfForm.txt"

    See for instance Arvin Meyers http://www.datastrat.com/Code/DocDatabase.txt
    Roy-Vidar

  6. #6
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Ok. Thank you very much Roy-Vidar and pootle flump! I guess the MSAccess code I opened had somehow set it to this option and my system was already set on "Break in Class Modules" or "Break on Unhandled Errors" which opening the other MSAccess app changed. I've never had to look at this option before and the article I read on the web wasn't 100% clear. I assumed it needed to be on "Break on all errors" but your info makes a lot of sense!!

    It all makes a lot of sense now and I see the code in the app which manipulates this (which to me seems dangerous as re-installing MSAccess/Office didn't re-set this option)! Again - thank you.
    Last edited by pkstormy; 05-28-07 at 12:36.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  7. #7
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    as a note on the /decompile - I had to do this quite a bit when I had MSAccess 2000 and 2002 installed on the same machine (until I found out what was going on)...

    I found that if you have both versions on the same machine and you import a form/report/module (in either 2000 or 2002) and don't immediately debug and compile after importing (i.e. you add some code), the database becomes "corrupt" and you need to use the /decompile option, delete the offending form/report/module, create a new one (same name), add a line of code, and debug/compile again, open in /decompile mode, delete the form/report/module, open again, re-import and "immediately" debug/compile. This was a BIG deal as we often imported code from one mdb to another and was a BIG pain when I went through the transition of upgrading to MSAccess 2002. I couldn't find the cause documented anywhere!! (I posted this solution on this forum previously). The problem went away when I got rid of 2000 (i.e. uninstalled both versions and just installed 2002).

    If you have both of these versions, please give it a try and let me know. It wasn't limited to just my machine and I'm curious if you can reproduce it on yours and any feedback/thoughts you might have.
    Last edited by pkstormy; 05-28-07 at 13:05.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  8. #8
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    Thank you for the kind words,

    My thoughts are limited by me never having more than one version of Office on a computer

    But I do know this was a problem with the 2000 version (http://support.microsoft.com/default...roduct=acc2000 *)), where I acquired the habit of always doing an explicit save and compile prior to running any code, which I'm still doing more or less automatically regardless of version

    After someone taught me about /decompile, that has fixed nearly all my corruption issues, except for some very few, where SaveAsText/LoadFromText did the trick, so I can't even remember the last time I imported to a new db to resolve corruption

    *) the "More information" section of the KB article, as I see it, more than suggests this might be a problem also for Office XP/2002, too, though I thought it was supposed to be fixed through some of the early SPs of the 2000 version.
    Roy-Vidar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •