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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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? |
Thread Tools | |
Display Modes | |
|
|