Calendars on a Subform

Tuesday, April 17, 2001 10:00:52

Note: this is derived from the other article Event Procedures on Subform Won't Work From Within Main Form

The steps are the same as detailed in the step-by-step instructions listed previously, except the code used in the Calender Control is different.

Assume the date field is called date_1, which is located in a form entitled log_form. This form is a subform within a form entitled main_form. The calendar control is called calendar_1, and it's located in a form named calendar_form.

The code normally used, as described in the step-by-step instructions would look like this:

Private Sub calendar_1_(Click)
' Set date_1 to the selected date and hide the calendar_1.
Forms![log_form]!date_1.Value = Forms![calendar_form]!calendar_1.Value
DoCmd.Close
End Sub

The 3rd line (in bold) is the one which had to be changed. Log_Form was the name of the form which had the date_1 field which was the field to be affected. The thing is, since log_form in this case was a subform, the syntax had to be changed to account for this. It was a subform under the main_form form. I noticed that the name of the this subform (log_form) control within "main_form" was, in fact, called "log_form." So the syntax of the line now becomes:

Forms![main_form]![log_form].Form!date_1.Value = Forms![calendar_form]!calendar_1.Value

The name main_form is the actual name of the parent form, and the name log_form is what the subform is called within this main form. And date_1 is the name of the field within log_form.