By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,686 Members | 2,589 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,686 IT Pros & Developers. It's quick & easy.

Microsoft Access - Filters Controlled via a combo box

P: 1
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:
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
Mar 26 '07 #1
Share this Question
Share on Google+
1 Reply


MMcCarthy
Expert Mod 10K+
P: 14,534
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
Mar 26 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.