473,418 Members | 2,049 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Programming Apply Filter Command Buttons That Use Queries

1
A couple years ago, I built a database in MS Access 2003. I built the form using macros in some of the command buttons, and now I’m trying to eliminate the macros and just use visual basic code. I’ve been successful in doing this for most of the buttons, but I’m having trouble reprogramming some Apply Filter buttons on one form and could use some help.

So I have a Contacts List form that lists all of the division’s staff members alphabetically by last name. There are three different departments in our division, each with its own filter button: AMMP, DMP, and HAV. Clicking the AMMP button shows an alphabetical list of that department’s staff, clicking DMP shows a different alphabetical list, etc. There’s also a Show All button that removes any filters and restores the original alphabetical list when clicked.

What I did originally was create a series of queries where I filtered the particular department I was interested in and sorted that department’s staff members alphabetically. So there was qryStaffAMMP for showing all of AMMP’s staff, qryStaffDMP for DMP staff, qryStaffHAV for HAV Staff, and qryStaff for showing the entire staff list alphabetically regardless of what department they came from. I linked these queries to macros and linked the Macros to the filter buttons on the Contacts List form. Now I want to take the macros out of the equation and have Visual Basic use these queries to filter the Contacts List form. Could anyone tell me how to do that?
Oct 29 '08 #1
1 3113
This answer may or may not work based on your table structure.

I would set your listbox source as only one query. Set up a combobox with a list of your department names (AMMP, DMP, and HAV). You can then specify your combobox as the criteria for the query. So instead of having LIKE "AMMP", you would have LIKE [FORMS]![FRMNAME]![COMBONAME]. In the combo properties, choose the AfterUpdate event and go to the VBA code. In the code, requery the listbox (ListboxName.requery). As you update the criteria in the combobox, the query criteria changes. When the criteria changes, your listbox will automatically update because of the combobox calling the AfterUpdate event which requeries the listbox.

That's how I would do it anyway.

-Kyle
Oct 29 '08 #2

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

Similar topics

16
by: Nhmiller | last post by:
I already have a report designed under Reports. When I use filtering in Forms or Tables, I see no way to select that filtered list when I am in Reports, and there appears to be no way to do the...
1
by: bjbounce2002 | last post by:
Hello, I am using forms with command buttons to close form or run action queries. The error messages such as "Null value in required field" or "duplicate value in primary key" are suppressed....
17
by: Liam.M | last post by:
Hey guys, Forgive me if my question my be alittle silly, but I would very much appreciate and assistance that could be given! My situation is as follows: I have created a Button, and set...
2
by: jcf378 | last post by:
hi all. I have a form which contains a calculated control ("days") that outputs the # of days between two dates (DateDiff command between the fields and ). However, when I click "Filter by...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
2
by: chiinook | last post by:
I have been creating a contact management database which now has about 300 records in it. I've been filtering using the "filter by form" command but I'd like to automate this with a set of buttons...
3
by: mattscho | last post by:
Hi All, Trying to create a set of 3 buttons in a form that have the same effect as the "Filter by Form", "Apply Filter" and "Remove Filter" Buttons on the access toolbar. Help would be muchly...
1
by: mattscho | last post by:
Re: Filter By From, Apply Filter, Remove Filter Buttons in a Form. -------------------------------------------------------------------------------- Hi All, Trying to create a set of 3 buttons in...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
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...
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...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.