vbacomboboxms-access-2010subforms

Driving a MS Access query in a subform form from the main form


I have a subform in datasheet form.

I want this subform to be filtered based on a combo box on the mainform. The data for the subform comes from a query. I have set the criteria of one of the fields of this query to be equal to:

    [Forms]![Form_Data_Update]![cbo_ReportSelection]

The mainform is Form_Data_Update and the combo box is cbo_ReportSelection.

to make the subform refresh when I change the combo box I have put in

    Private Sub cbo_ReportSelection_AfterUpdate()
    DoCmd.OpenQuery ("Aggregate_Leanboard_Discipline_Grouping")
    End Sub

Is there an alternate way that does not result in the query opening up in a new tab? I want it to just refresh in the subform. I tried:

    Me!Form_Leanboard_Discipline_Grouping_Subform.Requery

but that doesn't work i get an error '2465' Microsoft can't find the field 'Form_Leanboard_Discipline_Grouping_Subform'.

I am using Access 2010.

Thanks


Solution

  • The subform is contained in a subform control. Use the name of the subform control, not the name of the form. They may have different names.

    Private Sub cbo_ReportSelection_AfterUpdate()
        Me!SubformControlName.Form.Requery
    End Sub