OzzieTheOwl
Technical User
Hi
I am trying to apply a filter to a form using VBA, I need to the filter to work off ComboBox values the user has selected, and then apply the filter to several fields depending on what the user requests. I have written the code below, which works fine for one parameter, but when I select 2 parameters I get the following error message
I am probably missing something simple, any help would be appreciated.
Thanks
Barney
I am trying to apply a filter to a form using VBA, I need to the filter to work off ComboBox values the user has selected, and then apply the filter to several fields depending on what the user requests. I have written the code below, which works fine for one parameter, but when I select 2 parameters I get the following error message
Run-time error '2001'
You cancelled the previous operation.
Code:
Private Sub cmdApplyFilter_Click()
Dim txtRegFilter
Dim txtDateFilter
Dim txtProjectFilter
Dim txtTaskFilter
txtRegFilter = Form_Information.cmbRegSelect.Value
txtDateFilter = Form_Information.cmbWeekSelect.Value
txtProjectFilter = Form_Information.cmbProjectSelect.Value
txtTaskFilter = Form_Information.cmbTaskSelect.Value
If txtRegFilter <> "" Then Me.Form.Filter = "[Reg Number]='" & txtRegFilter & "'"
If txtDateFilter <> "" Then Me.Form.Filter = "[Week]='" & txtDateFilter & "'"
If txtProjectFilter <> "" Then Me.Form.Filter = "[Project Code]='" & txtProjectFilter & "'"
If txtTaskFilter <> "" Then Me.Form.Filter = "[Task Number]='" & txtTaskFilter & "'"
Me.FilterOn = True
Form_Information.cmbRegSelect.Value = ""
Form_Information.cmbWeekSelect.Value = ""
Form_Information.cmbProjectSelect.Value = ""
Form_Information.cmbTaskSelect.Value = ""
End Sub
I am probably missing something simple, any help would be appreciated.
Thanks
Barney