Search code examples
vbams-accessms-access-2007subformbeforeupdate

Losing ability to change properties when changing SourceObject of subform in Access 2007


I have a subform that changes where it gets its data from based on user input by using the Me.SubForm.SourceObject = Query.SomeQuery. It seems that by doing this, I am losing the ability to set the BeforeUpdate property.

The code I am using is as follows:

Forms![PartsDatabase]![RepsSubform].Form![Pack Rank].BeforeUpdate = "=ToTracking()"

I have confirmed that this works before the SubForm.SourceObject is changed, but afterwards it throws the following error: RTE 2455 "You entered an expression that has an invalid reference to the property BeforeUpdate."

I was wondering if this is a known issue or if I just need to modify my code to adjust.


Solution

  • You are getting things muddled up here. You should never be changing Source Objects, rather you should be changing the Record Source. The code involved in the Form is Form level. If you wish to use the Before Update event, it belongs to the Form and not the Recordsource. So you always go to change the RecordSource.

    You would use,

    Forms!Parentform!SubForm.Form.RecordSource = "SELECT someFields FROM someTable;"
    

    Or,

    Forms!ParentForm!SubForm.Form.RecordSource = "yourCompiledQueryName"