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

filter a combo box in a continuous form

P: 12
hi
i have a combo box in continuous form is there a way that i can filter the combo as i write in it?
Jul 14 '08 #1
Share this Question
Share on Google+
3 Replies


puppydogbuddy
Expert 100+
P: 1,923
Yes, highlight the combobox in design view, invoke the property sheet, then set the auto expand property to yes.
Jul 14 '08 #2

P: 12
this is not what i meant. what i need is to show the records that contain the characters that i wrote in the combo box
Jul 15 '08 #3

Expert Mod 2.5K+
P: 2,545
Hi dmcp. It would help us to help you if you would provide enough detail when asking a question so that our expert contributors, who give their time freely and voluntarily, are not misled. In your one-sentence question you did ask about filtering the combo as you wrote in it, not filtering your form. The answer given by Puppydogbuddy was accurate for the question you asked; unfortunately what you asked was not what you really meant.

After you have finished typing whatever characters you want to match into your combo you can apply a filter to the recordsource of your form using VBA code in the After Update event of your combo. You have not provided names of controls or underlying fields so the following skeleton code uses dummy names which you will need to replace.

In design mode select the combo and bring up its properties. Right click on the After Update event and select Build, Code. The VB Editor will be started with an empty After Update subroutine. Copy and paste the following, replacing the dummy names as appropriate:
Expand|Select|Wrap|Line Numbers
  1. Dim ComboContents as Variant
  2. ComboContents = Me![name of your combo control]
  3. If IsNull(ComboContents) then
  4.     Me.Filteron = False ' cancel filter if combo cleared
  5. else
  6.     Me.Filter = "[name of the field you want to filter] Like *" & ComboContents & "*"
  7.     Me.Filteron = True
  8. end if
This just applies a filter to the form on whatever field it is you want to filter. The wild card "*" characters are used to ensure matching on any text before and after the characters you want to find.

The filter is cancelled by clearing the combo box (tested for null above) but you may wish to put a command button on the form marked 'show all' to do this for your users instead.

-Stewart
Jul 15 '08 #4

Post your reply

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