I want to filter a subform based on two parameters on a form (combobox and textbox). I have a Form with combobox cboTimePeriod which show data from table TimePeriod (example TimePeriod=”-”; ID=12).
I want to use the value in the combobox to set the filter for subform.fired by the onchange event of the combobox. Experts Exchange. Individual Business Enterprise. Microsoft Access. Microsoft Access MS Access. Set SubForm Filter From Main Form Combobox. I have a combobox (cboperiodselect) in mainform. I want to use the value in the. Access-Diva provides custom databases using Microsoft Access utilizing SQL Server when called for. Linking Subforms to an Unbound Control(s) on the Main (Parent) Form. It will open blank until you make a selection from the Combo Box.
![Filter Filter](http://access-excel.tips/wp-content/uploads/2015/03/combo_box_01.jpg)
Combobox data: Data Row source= SELECT tblTimePeriod.TimePeriod, tblTimePeriod.ID FROM tblTimePeriod ORDER BY TimePeriod; Data Bound Column=2 (bound to ID) Format Column Count=1 (shows textual value of TimePeriod) Format List Width=2,54cm Also I have some cbobuttons with Cities, so when I press a button named 'Boston', TextBox txtCity shows i.e. What I want is when ever I select time period (cboTimePeriod), result in a subform has to be filtered based on these two parameters (selected TimePeriod AND City in textbox). And as you might guessed, it does not work. I tried several codes, here is the one I've used: ' And this is my implementation, which does not work: Dim strWhere As String If Nz(Me.cboTimePeriod, ') ' Then strWhere = strWhere & 'TimePeriodID = ' & Trim(Me. CboTimePeriod) & ' ' AND ' End If If Nz(Me.txtSelectedCity, ') ' Then strWhere = strWhere & 'CityName = ' & Trim(Me. TxtSelectedCity) & ' ' AND ' End If If strWhere ' Then strWhere = Left(strWhere, Len(strWhere) - 5) Me.qrySomeDatasubform.Form.Filter = strWhere 'after this line, function exits the code Me.qry SomeDatasubform.Form.FilterOn = True Else Me.qry SomeDatasubform.Form.Filter = ' Me.qry SomeDatasubform.Form.FilterOn = False End If strWhere gives this: strWhere = 'TimePreriodID = '12 ' AND CityName = 'Boston ' After aplying a filter, on a subform 'Unfiltered' changes to 'Filtered', but with no change in data. Any help is appreciated.