From: Stewart Berman on 17 Nov 2009 01:52 Apologies for posting in two newsgroups but after I originally posted it in forms I realized this should have been posted here (formscoding) instead. Access 2007 This only happens on some machines. It has occurred on a PC running Windows XP SP3 and a MAC running Windows. I have been unable to reproduce it on other PCs running Windows XP SP3, Vista or Windows 7. On the machines that have the problem it always occurs. I have a form with a sub form control. The control's SourceObject is changed depending on the function required. On the forms that is used in the control is a utility form that does not reference data through the form containing the control. One of the functions in the utility form changes the Filter and RecordSource of the main form. Actually, it saves the values and then clears them. Later on it restores the values. The code looks like: Dim sFilter As String Dim sRecordSource As String <snip> sFilter = Me.Parent.Filter sRecordSource = Me.Parent.RecordSource Me.Parent.Filter = "" Me.Parent.RecordSource = "" If ("\" <> Right$(sBackupDirectory, 1)) Then sBackupDirectory = sBackupDirectory & "\" End If If I step through the code instead of going from the Me.Parent.RecordSource = "" line to the If statement the code goes to the Form_Open followed by Form_Load sub routines. When the Form_Load sub routine completes the If statement is executed. It looks like Access is reloading the form. However, at that point the Me object is trashed. That is the code will continue to run but it has lost its reference to itself. If I try to look at a property using the Me reference (i.e. ?Me.Parent.Name) the system throws an error saying the object reference is invalid. But it does not throw an error when the utility function tries to restore the parent's Filter and RecordSource: Me.Parent.RecordSource = sRecordSource Me.Parent.Filter = sFilter Of course they not actually restored. Has anyone seen this type of behavior and if so is there a work around?
From: Paul Shapiro on 17 Nov 2009 08:27 Are all the machines fully patched for Office 2007? Maybe Office service pack level and/or later hotfixes are different/missing? Nothing you're describing sounds like it would be OS or machine-dependent. Are you sure it's the Me reference that is no longer valid? You gave the example of Me.Parent, and after the parent form has been reloaded it might make sense that Me.Parent is no longer valid. It's unusual to have a subform modifying the parent form settings. Maybe you could raise a custom event in the subform and let the parent form take action in response to that event? Or make the utility subform a separate form rather than a subform. Then it could refresh it's reference to the current parent form using the Forms collection if the parent form reference becomes invalid. "Stewart Berman" <saberman(a)nospam.nospam> wrote in message news:0qh4g5di2pamk6r4pssa4ttm0kmmpmheke(a)4ax.com... > Apologies for posting in two newsgroups but after I originally posted it > in forms I realized this > should have been posted here (formscoding) instead. > > Access 2007 > > This only happens on some machines. It has occurred on a PC running > Windows XP SP3 and a MAC > running Windows. I have been unable to reproduce it on other PCs running > Windows XP SP3, Vista or > Windows 7. On the machines that have the problem it always occurs. > > I have a form with a sub form control. The control's SourceObject is > changed depending on the > function required. On the forms that is used in the control is a utility > form that does not > reference data through the form containing the control. One of the > functions in the utility form > changes the Filter and RecordSource of the main form. Actually, it saves > the values and then clears > them. Later on it restores the values. The code looks like: > > Dim sFilter As String > Dim sRecordSource As String > > <snip> > sFilter = Me.Parent.Filter > sRecordSource = Me.Parent.RecordSource > Me.Parent.Filter = "" > Me.Parent.RecordSource = "" > If ("\" <> Right$(sBackupDirectory, 1)) Then > sBackupDirectory = sBackupDirectory & "\" > End If > > If I step through the code instead of going from the > Me.Parent.RecordSource = "" line to the If > statement the code goes to the Form_Open followed by Form_Load sub > routines. When the Form_Load sub > routine completes the If statement is executed. It looks like Access is > reloading the form. > However, at that point the Me object is trashed. That is the code will > continue to run but it has > lost its reference to itself. If I try to look at a property using the Me > reference (i.e. > ?Me.Parent.Name) the system throws an error saying the object reference is > invalid. > > But it does not throw an error when the utility function tries to restore > the parent's Filter and > RecordSource: > Me.Parent.RecordSource = sRecordSource > Me.Parent.Filter = sFilter > Of course they not actually restored. > > Has anyone seen this type of behavior and if so is there a work around?
From: Stewart Berman on 17 Nov 2009 23:15 It is definitely the Me reference that dead. Even: ?Me.name Fails. I changed the code to: Me.Parent.Recordset.close Me.Parent.Filter = "" Me.Parent.RecordSource = "" And it throws: Run-time error '2567: The expression you entered refers to an object that is closed or doesn't exist. At the second line. "Paul Shapiro" <paul(a)hideme.broadwayData.com> wrote: >Are all the machines fully patched for Office 2007? Maybe Office service >pack level and/or later hotfixes are different/missing? Nothing you're >describing sounds like it would be OS or machine-dependent. > >Are you sure it's the Me reference that is no longer valid? You gave the >example of Me.Parent, and after the parent form has been reloaded it might >make sense that Me.Parent is no longer valid. It's unusual to have a subform >modifying the parent form settings. Maybe you could raise a custom event in >the subform and let the parent form take action in response to that event? >Or make the utility subform a separate form rather than a subform. Then it >could refresh it's reference to the current parent form using the Forms >collection if the parent form reference becomes invalid. > >"Stewart Berman" <saberman(a)nospam.nospam> wrote in message >news:0qh4g5di2pamk6r4pssa4ttm0kmmpmheke(a)4ax.com... >> Apologies for posting in two newsgroups but after I originally posted it >> in forms I realized this >> should have been posted here (formscoding) instead. >> >> Access 2007 >> >> This only happens on some machines. It has occurred on a PC running >> Windows XP SP3 and a MAC >> running Windows. I have been unable to reproduce it on other PCs running >> Windows XP SP3, Vista or >> Windows 7. On the machines that have the problem it always occurs. >> >> I have a form with a sub form control. The control's SourceObject is >> changed depending on the >> function required. On the forms that is used in the control is a utility >> form that does not >> reference data through the form containing the control. One of the >> functions in the utility form >> changes the Filter and RecordSource of the main form. Actually, it saves >> the values and then clears >> them. Later on it restores the values. The code looks like: >> >> Dim sFilter As String >> Dim sRecordSource As String >> >> <snip> >> sFilter = Me.Parent.Filter >> sRecordSource = Me.Parent.RecordSource >> Me.Parent.Filter = "" >> Me.Parent.RecordSource = "" >> If ("\" <> Right$(sBackupDirectory, 1)) Then >> sBackupDirectory = sBackupDirectory & "\" >> End If >> >> If I step through the code instead of going from the >> Me.Parent.RecordSource = "" line to the If >> statement the code goes to the Form_Open followed by Form_Load sub >> routines. When the Form_Load sub >> routine completes the If statement is executed. It looks like Access is >> reloading the form. >> However, at that point the Me object is trashed. That is the code will >> continue to run but it has >> lost its reference to itself. If I try to look at a property using the Me >> reference (i.e. >> ?Me.Parent.Name) the system throws an error saying the object reference is >> invalid. >> >> But it does not throw an error when the utility function tries to restore >> the parent's Filter and >> RecordSource: >> Me.Parent.RecordSource = sRecordSource >> Me.Parent.Filter = sFilter >> Of course they not actually restored. >> >> Has anyone seen this type of behavior and if so is there a work around?
From: Stewart Berman on 17 Nov 2009 23:23 I forgot to mention that it happened on a machine that did not have Access 2007 install -- just the runtime version that was installed as part of this product. Other machines without Access 2007 installed that had the runtime installed as part of this product do not exhibit this behavior. So the machines with only the runtime are running the exact same version of Access 2007 runtime as it was installed with the product. "Paul Shapiro" <paul(a)hideme.broadwayData.com> wrote: >Are all the machines fully patched for Office 2007? Maybe Office service >pack level and/or later hotfixes are different/missing? Nothing you're >describing sounds like it would be OS or machine-dependent. > >Are you sure it's the Me reference that is no longer valid? You gave the >example of Me.Parent, and after the parent form has been reloaded it might >make sense that Me.Parent is no longer valid. It's unusual to have a subform >modifying the parent form settings. Maybe you could raise a custom event in >the subform and let the parent form take action in response to that event? >Or make the utility subform a separate form rather than a subform. Then it >could refresh it's reference to the current parent form using the Forms >collection if the parent form reference becomes invalid. > >"Stewart Berman" <saberman(a)nospam.nospam> wrote in message >news:0qh4g5di2pamk6r4pssa4ttm0kmmpmheke(a)4ax.com... >> Apologies for posting in two newsgroups but after I originally posted it >> in forms I realized this >> should have been posted here (formscoding) instead. >> >> Access 2007 >> >> This only happens on some machines. It has occurred on a PC running >> Windows XP SP3 and a MAC >> running Windows. I have been unable to reproduce it on other PCs running >> Windows XP SP3, Vista or >> Windows 7. On the machines that have the problem it always occurs. >> >> I have a form with a sub form control. The control's SourceObject is >> changed depending on the >> function required. On the forms that is used in the control is a utility >> form that does not >> reference data through the form containing the control. One of the >> functions in the utility form >> changes the Filter and RecordSource of the main form. Actually, it saves >> the values and then clears >> them. Later on it restores the values. The code looks like: >> >> Dim sFilter As String >> Dim sRecordSource As String >> >> <snip> >> sFilter = Me.Parent.Filter >> sRecordSource = Me.Parent.RecordSource >> Me.Parent.Filter = "" >> Me.Parent.RecordSource = "" >> If ("\" <> Right$(sBackupDirectory, 1)) Then >> sBackupDirectory = sBackupDirectory & "\" >> End If >> >> If I step through the code instead of going from the >> Me.Parent.RecordSource = "" line to the If >> statement the code goes to the Form_Open followed by Form_Load sub >> routines. When the Form_Load sub >> routine completes the If statement is executed. It looks like Access is >> reloading the form. >> However, at that point the Me object is trashed. That is the code will >> continue to run but it has >> lost its reference to itself. If I try to look at a property using the Me >> reference (i.e. >> ?Me.Parent.Name) the system throws an error saying the object reference is >> invalid. >> >> But it does not throw an error when the utility function tries to restore >> the parent's Filter and >> RecordSource: >> Me.Parent.RecordSource = sRecordSource >> Me.Parent.Filter = sFilter >> Of course they not actually restored. >> >> Has anyone seen this type of behavior and if so is there a work around?
From: "Charles Wang [MSFT]" on 18 Nov 2009 01:58
Hi, Since this issue does not appear on your other machines, I think that this should not be a coding issue. Probably some components were not installed. Since you were using RecordSource, I would like to check with you besides Access runtime, did you also install Data Connectivity Components? I suggest that you also install this component and make sure that you apply the latest update. 2007 Office System Driver: Data Connectivity Components http://www.microsoft.com/downloads/details.aspx?FamilyID=7554f536-8c28-4598- 9b72-ef94e038c891&DisplayLang=en Microsoft Office Access Runtime and Data Connectivity 2007 Service Pack 2 (SP2) http://www.microsoft.com/downloads/details.aspx?FamilyId=6F4EDEED-D83F-4C31- AE67-458AE365D420&displaylang=en Best regards, Charles Wang |