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. -
Public Function frmSearch_cbxFilter(Optional clear As Boolean)
-
-
Dim frm As Form
-
Dim sbFrm As SubForm
-
Dim ctrl As Control
-
Dim cbxItem As Variant
-
Dim cbxValue As Variant
-
Dim strFilter As String
-
Dim count As Integer
-
Dim i As Integer
-
-
Set frm = Forms!frmSearch
-
Set sbFrm = frm!sbfrmProdDetailSearch
-
-
cbxItem = Array("cbxUser", "cbxDepartment", "cbxComment") '"Named" Comboboxes
-
cbxValue = Array("userID", "departmentID", "commentID") 'Filter Fields | Count must match cbxItem
-
count = UBound(cbxItem, 1) 'Number of elements in array
-
-
strFilter = "1=1"
-
-
If clear Then 'Clear set to true
-
For i = 0 To count
-
For Each ctrl In frm.Controls 'Every control on form
-
If ctrl.Name = cbxItem(i) Then 'Only "Named" controls on form
-
ctrl.Value = "" 'Clear control value
-
End If
-
Next
-
Next
-
sbFrm.Form.FilterOn = False
-
Else 'Clear not set
-
For i = 0 To count
-
For Each ctrl In frm.Controls 'Every control on form
-
If ctrl.Name = cbxItem(i) Then 'Only "Named" controls on form
-
If Not IsNull(ctrl.Column(1)) Then 'Only update filter if control contains a value
-
strFilter = strFilter & " AND [" & cbxValue(i) & "]=" & ctrl.Column(1) 'Build filter
-
End If
-
End If
-
Next
-
Next
-
-
sbFrm.Form.Filter = strFilter
-
sbFrm.Form.FilterOn = True
-
End If
-
-
End Function
Good Luck. :)
5 10832
Wow! I posted this over a year ago (I think, seems that long) and no responses... Hope this helped somebody out.
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.
:)
Thanks Mary. Just trying to give back a little to a site that's helped me so much.
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
Thanks for the reply Jim. I'm glad this helped you out.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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
|
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
|
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...
| |
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...
|
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...
|
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...
|
by: jvan2008 |
last post by:
"Form1"
combobox "cboModel"
Row Source
SELECT ., . FROM tblModel ORDER BY ;
combobox "cboContactName"
SELECT . FROM Query1 ORDER BY ;
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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();...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |