Hello,
I'm using the following code, which resides in a form (which is a subform on a main report):
Code:
Private Sub Report_Load()
Me.lblWk1.Caption = CStr(Date - DatePart("w", Date) + 2)
Me.lblWk2.Caption = CStr((Date - DatePart("w", Date) + 2) - 7)
Me.lblWk3.Caption = CStr((Date - DatePart("w", Date) + 2) - 14)
Me.lblWk4.Caption = CStr((Date - DatePart("w", Date) + 2) - 21)
Me.lblWk5.Caption = CStr((Date - DatePart("w", Date) + 2) - 28)
Me.lblWk6.Caption = CStr((Date - DatePart("w", Date) + 2) - 35)
Me.txtWk1.ControlSource = CStr(Me.lblWk1.Caption)
Me.txtWk2.ControlSource = CStr(Me.lblWk2.Caption)
Me.txtWk3.ControlSource = CStr(Me.lblWk3.Caption)
Me.txtWk4.ControlSource = CStr(Me.lblWk4.Caption)
Me.txtWk5.ControlSource = CStr(Me.lblWk5.Caption)
Me.txtWk6.ControlSource = CStr(Me.lblWk6.Caption)
End Sub
When I load the subform in it's own window, the code works without error and gives me the intended results (the report displays the results of a crosstab query which shows the last 6 weeks' data--so is dynamic, hence the code above). However, when the main form loads, I get "runtime error 2467: the expression you entered refers to an object that is closed or doesn't exist". I'm not quite sure how I should be referring to the object(s) to make sure the subform headers and controls display properly. How do I correctly reference the subform controls?
Thanks