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 10772
Wow! I posted this over a year ago (I think, seems that long) and no responses... Hope this helped somebody out.
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.
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: jvan2008 |
last post by:
"Form1"
combobox "cboModel"
Row Source
SELECT ., . FROM tblModel ORDER BY ;
combobox "cboContactName"
SELECT . FROM Query1 ORDER BY ;
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
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...
|
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...
| |