Hoping someone can advise on this one. I have some code that, when a button is clicked, activates a dropdown on a form and changes the source object of a subform. This is working ok, but after opening, the source object won't refresh. The data it displays is dependent on the value in the dropdown, which defaults to the current reporting period. The code is:
Private Sub cmd_View_By_Period_Click()
Dim var_Today As Date
var_Today = Date
Me.cmb_RepPeriod_MgmrTasks.Enabled = True
cmb_RepPeriod_MgmrTasks.Value = DLookup("Period_ID", "tbl_Rep_Period", "#" & Format(var_Today, "mm-dd-yyyy") & "# BETWEEN Start_Date AND End_Date")
Me.frm_ManagerTasks.SourceObject = "frm_ManagerTasks_Period"
Forms!frm_Manager_Dashboard!frm_ManagerTasks.Requery
End Sub
Thanks in advance.
1) The Recordsource of the form being used as a Subform
2) The Master/Child linking fields defined on the Subform Control in the parent form
Your code does nothing more than simply set the SourceObject (and BTW there is no need to Requery - this will occur when the SourceObject is loaded). Check the Recordsource and Master/Child link fields to insure they're setup correctly.
do you mean that you WANT the Subform data to be dependant on the cmb_RepPeriod_MgmrTasks value? If so, then either (a) filter the subform's recordsource or (b) apply a Filter to that subform. You'd do this AFTER opening the subform. Assuming you want to use the same filter as your DLookup, you'd do this:
Me.frm_ManagerTasks.Form.F
Me.frm_ManagerTasks.Form.F
I'm not sure where you're defining "Start_Date" and "End_Date", so be careful to insure that those actually have a Value. Are these controls on a form, or variables defined somewhere else?