473,383 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,383 developers and data experts.

Multiple Combobox Filter with Clear Option

aas4mis
97
I haven't had much luck with specific controls, their properties and loops in the past. I thought I would share this tidbit of code, feel free to modify/modularize in any way to suit your needs. This function may be called from the combobox after_update event or a "clear filter" buttons after_update event. I placed this in a module. Oh, one more thing... I happened to have my FK in column 1 of the combobox, this may need changed. Sorry if I "over commented", I have been lost so many times due to poor comments. If there is a better way to accomplish this please feel free to let me know, from my experience vba for access is limited in this area.
Expand|Select|Wrap|Line Numbers
  1. Public Function frmSearch_cbxFilter(Optional clear As Boolean)
  2.  
  3. Dim frm As Form
  4. Dim sbFrm As SubForm
  5. Dim ctrl As Control
  6. Dim cbxItem As Variant
  7. Dim cbxValue As Variant
  8. Dim strFilter As String
  9. Dim count As Integer
  10. Dim i As Integer
  11.  
  12.     Set frm = Forms!frmSearch
  13.     Set sbFrm = frm!sbfrmProdDetailSearch
  14.  
  15.     cbxItem = Array("cbxUser", "cbxDepartment", "cbxComment")   '"Named" Comboboxes
  16.     cbxValue = Array("userID", "departmentID", "commentID")     'Filter Fields | Count must match cbxItem
  17.     count = UBound(cbxItem, 1)                                  'Number of elements in array
  18.  
  19.     strFilter = "1=1"
  20.  
  21.     If clear Then                                               'Clear set to true
  22.         For i = 0 To count
  23.             For Each ctrl In frm.Controls                       'Every control on form
  24.                 If ctrl.Name = cbxItem(i) Then                  'Only "Named" controls on form
  25.                     ctrl.Value = ""                             'Clear control value
  26.                 End If
  27.             Next
  28.         Next
  29.         sbFrm.Form.FilterOn = False
  30.     Else                                                        'Clear not set
  31.         For i = 0 To count
  32.             For Each ctrl In frm.Controls                       'Every control on form
  33.                 If ctrl.Name = cbxItem(i) Then                  'Only "Named" controls on form
  34.                     If Not IsNull(ctrl.Column(1)) Then          'Only update filter if control contains a value
  35.                         strFilter = strFilter & " AND [" & cbxValue(i) & "]=" & ctrl.Column(1) 'Build filter
  36.                     End If
  37.                 End If
  38.             Next
  39.         Next
  40.  
  41.         sbFrm.Form.Filter = strFilter
  42.         sbFrm.Form.FilterOn = True
  43.     End If
  44.  
  45. End Function
Good Luck. :)
Jan 23 '09 #1
5 10772
aas4mis
97
Wow! I posted this over a year ago (I think, seems that long) and no responses... Hope this helped somebody out.
Dec 21 '09 #2
MMcCarthy
14,534 Expert Mod 8TB
You got 863 views, so I wouldn't worry too much. Most insights don't get a lot of comments so view count is a better indicator.
Dec 23 '09 #3
aas4mis
97
:)

Thanks Mary. Just trying to give back a little to a site that's helped me so much.
Dec 23 '09 #4
jimatqsi
1,271 Expert 1GB
Oh, I like this. I make a lot of forms with multiple filter selections in the heading of the form, and this might simplify things greatly.

I often use check boxes and text boxes, so I'd like to expand on this a bit. Maybe by adding some other arrays to specify the SQL code that goes along with a particular selection of a particular control.

Very interesting. Thanks!

Jim
Jun 12 '10 #5
aas4mis
97
Thanks for the reply Jim. I'm glad this helped you out.
Jun 14 '10 #6

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

Similar topics

2
by: Vern | last post by:
I have a combobox called sPropertyCountyCd whose datasource is a dataview. The first time I set the filter to the dataview, attach the combobox to the dataview, and set the selected index to -1 is...
2
by: fstenoughsnoopy | last post by:
I have a customer order database and I need to pull a customers information, ie first name, last name, address, city, state, zip, phone, etc, into the oder table. i don't know how to go about...
1
by: favor08 | last post by:
I need help with a big project. I am struggle getting multiple option buttons and filters to work together. They need to be able to filter a subform. My first set of option buttons work fine all...
4
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
I am trying to populate a DataGridView Combobox column with a different data binding source (dataset) depending upon a selection made in a previous column. I can handle the previous column but how...
1
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just...
1
by: sjarmy | last post by:
I am using javascript to make a dropdownlist act like a combobox and it is work well. The issue I'm having is when the user types in the combobox and finds the selection he wants, he has to use the...
1
by: viranadim | last post by:
I am having problems with attempting to filter a form based on criteria selected in a combo box from another form. I am attempting to filter a form called "Ford CheckList" that is based on a table...
3
by: tragic54 | last post by:
Alright so im having a problem getting a value from a couple combo boxes based on their index. Im calling the objects from the main form to calculatecost() from 2 other classes. Anyways heres the...
4
by: jvan2008 | last post by:
"Form1" combobox "cboModel" Row Source SELECT ., . FROM tblModel ORDER BY ; combobox "cboContactName" SELECT . FROM Query1 ORDER BY ;
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.