Friday, June 24, 2016

Access VBA- Filter subform

MS-ACCESS VBA: FILTER SUBFORM RECORDS USING COMBOBOX



Steps:
1. Create a blank form as Main Form and place a combo box on it. Also place a button to clear the filter.
2. Place the subform by dragging the Mobiles table.
3. Create a query on Mobiles table to fetch the unique records from Brand column.
4. Use the above query as Row Source of the combobox.
5. Select the combo box and set BoundColumn=1, ColumnCount=1,ColumnWidth=1
6. Now Apply the following event procedures on the ClearFilter button and ComboBox.

Option Compare Database
Option Explicit
Private Sub cmdClearFilter_Click()
    Me.Combo5.Value = ""
    Me.Mobiles_subform.Form.FilterOn = False
End Sub

Private Sub Combo5_AfterUpdate()

    Me.Mobiles_subform.Form.Filter = ""
    Me.Mobiles_subform.Form.FilterOn = False
    Me.Mobiles_subform.Form.Filter = "[Brand] Like'*" & Me.Combo5.Value & "*'"
    Me.Mobiles_subform.Form.FilterOn = True

End Sub




No comments:

Post a Comment

Hot Topics