Connecting Tech Pros Worldwide Forums | Help | Site Map

Microsoft Access - Filters Controlled via a combo box

Newbie
 
Join Date: Mar 2007
Location: United Kingdom
Posts: 1
#1: Mar 26 '07
Hello,
I am currently working on a Stock Control database and I am trying to set a filter on the form using a combo box.

At present I am using a continuous form with the combo box being placed in the header so that it is always viewable.

I have put the code in to the form however every time i select anything in the combo box I get an error message saying:
Quote:
run-time error '2501':
The ApplYFilter action was canceled
The combo box name is: cmbProductSearch

The code that I have in place is:
Expand|Select|Wrap|Line Numbers
  1. 'filter that is used to filter the records based on product name
  2. Private Sub cmbProductSearch_Change()
  3.  
  4. currentFilter = "((((tblProducts.ProductDescription) = " + "'" + cmbProductSearch + "')))"
  5.  
  6. Filter = currentFilter
  7.  
  8. DoCmd.ApplyFilter , Filter
  9.  
  10. End Sub
  11.  
I have tried using both Access 2003 and Access XP
I have used Windows XP Home and Windows XP Professional

I would really appreciate any help on this as I seem to have hit a very large brick wall as I have now tried many different things that I have found on the web.

Best Regards,
Ben

msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,885
#2: Mar 26 '07

re: Microsoft Access - Filters Controlled via a combo box


Hi Ben,

Q. where is currentFilter defined?

Also you have to use '&' not '+' as follows:

Expand|Select|Wrap|Line Numbers
  1. 'filter that is used to filter the records based on product name
  2. Private Sub cmbProductSearch_Change()
  3.  
  4. currentFilter = "[ProductDescription] = '" & Me!cmbProductSearch & "'"
  5.  
  6. Filter = currentFilter
  7.  
  8. DoCmd.ApplyFilter , Filter
  9.  
  10. End Sub
  11.  

Mary
Reply