A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Urgent: Changing RecordSource Causes A Reload of Sub Form Destroying References



 
 
Thread Tools Display Modes
  #1  
Old November 17th, 2009, 07:34 AM posted to microsoft.public.access.forms
Stewart Berman
external usenet poster
 
Posts: 68
Default Urgent: Changing RecordSource Causes A Reload of Sub Form Destroying References

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?
  #2  
Old November 17th, 2009, 06:55 PM posted to microsoft.public.access.forms
Daryl S[_2_]
external usenet poster
 
Posts: 881
Default Urgent: Changing RecordSource Causes A Reload of Sub Form Destroyi

Stewart -

One way to not lose the variables in the subform when re-loading the parent
form (due to the filter change) is to put your data in unbound hidden fields
on the parent form. Then they won't get wiped out when filter is applied on
the parent form.

--
Daryl S


"Stewart Berman" wrote:

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?
.

  #3  
Old November 18th, 2009, 05:18 AM posted to microsoft.public.access.forms
Stewart Berman
external usenet poster
 
Posts: 68
Default Urgent: Changing RecordSource Causes A Reload of Sub Form Destroyi

I am a little confused. The parent form is not reloading -- the sub form is and it is changing the
RecordSource that triggers it not changing the filter. Why would this happen on some machines and
not others?

Daryl S wrote:

Stewart -

One way to not lose the variables in the subform when re-loading the parent
form (due to the filter change) is to put your data in unbound hidden fields
on the parent form. Then they won't get wiped out when filter is applied on
the parent form.

  #4  
Old November 18th, 2009, 03:28 PM posted to microsoft.public.access.forms
Daryl S[_2_]
external usenet poster
 
Posts: 881
Default Urgent: Changing RecordSource Causes A Reload of Sub Form Dest

Stewart -

The Me.Parent construct refers to the parent, or main form, so your code is
changing the recordsource of the main form.

--
Daryl S


"Stewart Berman" wrote:

I am a little confused. The parent form is not reloading -- the sub form is and it is changing the
RecordSource that triggers it not changing the filter. Why would this happen on some machines and
not others?

Daryl S wrote:

Stewart -

One way to not lose the variables in the subform when re-loading the parent
form (due to the filter change) is to put your data in unbound hidden fields
on the parent form. Then they won't get wiped out when filter is applied on
the parent form.

.

  #5  
Old November 20th, 2009, 07:14 AM posted to microsoft.public.access.forms
Stewart Berman
external usenet poster
 
Posts: 68
Default Urgent: Changing RecordSource Causes A Reload of Sub Form Dest

Yes, but it is the sub form that is reloaded -- not the parent.

Daryl S wrote:

Stewart -

The Me.Parent construct refers to the parent, or main form, so your code is
changing the recordsource of the main form.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:36 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.