Question : change a sourceobject for a subform

I have a main form called Employees
I have tabs on this main form Employee and on on of the pages called pgLife I have a subform called Life_Events

I would like when the form is open that macro run that runs a code (runcode) that runs a function that will change the sourceobject from Life_Events to Daily_Events

The Link Master Fields and Link Child Fileds are Employee ID

Right now when the form open I get a Halt error and the subform is still showing the original form.  I know I can just replace the source object and save the form but for other reason I need to have the subform switched out through code.
Code Snippet:
1:
2:
3:
4:
Public Function DHMRI_frm_CustomerProjects()
    [Forms]![Employee]![Life_Events].[SourceObject] = "Daily_Events"
  [Forms]![Employee]![Life_Events].[LinkMasterFields] = "EmployeeID"
  [Forms]![Employee]![Life_Events].[LinkChildFields] = "EmployeeID"

Answer : change a sourceobject for a subform

Is Employee the name of your main form?
Is Life_Events the name of the subform control on the main form?
Are you executing the code from the main form?
              try it this way:  Forms!Employee!Life_Events.Form.SourceObject = "Daily_Events"
                                                                                      ^^^^^
If  your code is executing from the subform source object and not from the main form, the syntax would probably be as follows:  Me.SourceObject= "Daily_Events"
Random Solutions  
 
programming4us programming4us