473,765 Members | 1,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple Combobox Filter with Clear Option

aas4mis
97 New Member
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 10832
aas4mis
97 New Member
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 Recognized Expert Moderator MVP
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 New Member
:)

Thanks Mary. Just trying to give back a little to a site that's helped me so much.
Dec 23 '09 #4
jimatqsi
1,276 Recognized Expert Top Contributor
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 New Member
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
2234
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 comes up correctly as blank. However, if I change the filter, and set the selected index to -1, is always shows the first record from the dataview and changes the index to 0. I even tried to set the datasource to null, and then reassigning the...
2
946
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 making this work...
1
6442
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 past due demand fax and my combo boxes work fine opid prodcd
4
6040
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 do I assign the following properties dynamically in code? DataPropertyName DataSource DisplayMember I do see how to set these at design time but that won't do because I need
1
8063
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 a commandbutton on my form). The biggest problem I'm having is that I can't (don't know how) populate a combobox on static items such as "True, False, Any." The Any field, would be selected by the user to find all records where that fields is...
1
2192
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 mouse to make the actual selection. The user wants to have the option of just hitting the enter key instead of using the mouse. He also wants to use the tab key to move to the next field. I'm using onkeydown to call the javascript, and I know I need...
1
2506
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 called "Ford Returned Warranty Parts List". I am using the catagory "Program" that is in a combobox called "Program_Combo" which is located on a form called "Ford Database: Choose an Option". I want the user to open the form "Ford Database: Choose an...
3
1484
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 main form code and i'll post one class after that with the combo box selected values. Option Strict On Option Explicit On Public Class MobilePhoneCost Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As...
4
3511
by: jvan2008 | last post by:
"Form1" combobox "cboModel" Row Source SELECT ., . FROM tblModel ORDER BY ; combobox "cboContactName" SELECT . FROM Query1 ORDER BY ;
0
9566
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10153
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7371
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6646
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5272
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3530
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.