Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Filter Toggle Button
Amir Ouranus 
      
5 months ago
Hello,
I just watched Access Advanced 2, and I wanted to add a toggle button to my form so I can turn of and on the filter for people whom are active or all people (including terminated and Inactive) people.

If the filter is on the toggle button should say Active Only (or something like that) if I click on the toggle button again it turns off the filter and the button says All Employees.

Thank you in advance for any help you can provide.
Amir Ouranus
Donald Blackwell  @Reply  
       
5 months ago
Are you wanting to do it with a Macro or with VBA? Don't want to get to far ahead.

In either case, you'll check the value of the toggle button, if it's checked/pressed, you'll set the caption property to "Active Employees" and if it's not, set the caption property to "All Employees", or whatever text you choose.

Then you'd have to set the value of the form's Filter to isActive = True if checked or to blank if not. You could technically leave it always "isActive = True" and only toggle the FilterOn property, however, the user might change the filter using the right-click menu if it's available or the ribbon which would then potentially effect how your form works.

Then, as mentioned above, you'd have to set the form's FilterOn property to True or False.

Each of these steps is a little different depending on whether or not you are using a Macro or VBA.
Amir Ouranus OP  @Reply  
      
5 months ago
Hi Donald,
Right now I'm doing it in Macro, because I'm at Advanced 2.
But if you think VBA would be easier, I can wait until I'm taking those classes.
I'll be done with the Advanced classes pretty soon; so, again I can wait.
Donald Blackwell  @Reply  
       
5 months ago
It's not that it's hard in macros, just, in my opinion more tedious. Almost every line of code in VBA seemingly gets broken down to 3 or more lines each in a Macro

In the events tab for your toggle button, you would go into the Macro Editor for the After Update event for the toggle button.

In the Editor:
1. Click "Show All Actions" at the top
2. In the dropdown, type "If" and press tab
3. In the next field, type the name of your toggle button control and click "Then"
    Note This indicates to do something if the toggle button is pressed
4. In the next field, type (or choose) "SetValue" then tab
5. In the Item field, type form.Filter and tab
6. In the Expression field, type ="IsActive=True" and tab
7. In the next drop down, type or choose "SetProperty" and tab
8. In the Control Name field, enter the name of you toggle button and tab
9. In the Property Field, type or choose "Caption" and tab
10. In the Value Field, type "Show All Employees" (or whatever you want for when the toggle button is pressed) then click "Else"
Then, repeat steps 4 through 10, with the following changes:
Step 6, change the Expression to =""
Step 10, change the Value to "Show Active Employees" (or whatever you want of when the toggle isn't pressed)
tab until your in the drop down AFTER "End If"

18. Type or choose "SetValue" again and tab
19. In the Item field, type form.FilterOn and tab
20. In the Expression field, type =Toggle and tab (where Toggle is the name of your ToggleButton)
Make sure you're in an empty field (or at least that you don't have any text selected) and save your Macro

The last line is because of a bug that used to exist in Access, but if you had text selected in the Macro editor with more than a few items and you clicked save or close macro editor, the editor and Access would crash and you'd lose all your work in the editor and any unsaved work in your form. Since I haven't worked in the editor in a while, I'm not sure if it's fixed, but I dealt with the consequences of every time I forgot for over a year until I started with VBA.
Donald Blackwell  @Reply  
       
5 months ago
The same process uses about 7 lines of code in VBA not including blank lines or comments if you make your code easy to read.
Amir Ouranus OP  @Reply  
      
5 months ago
Hi Donald,
Thank you for that; however, I am getting an error on that.
Here's the error:

The object doesn't contain the Automation object 'Toggle'.
You Tried to run a Visual Basic procedure to set a property or method for an object.
However, the component doesn't make the property or method available for Automation.
Check the component's documentation for information on the properties and methods it makes available for Automation operations.
Ben Perry  @Reply  
       
5 months ago
It sounds like you are trying to do the exact same thing I did. I will attach some pictures of my macro setup. For me to get it to work, I needed to create it as a standalone macro (not an embedded one) then call the standalone from the forms OnLoad/OnOpen event to get it to set 'default' then call it again in the buttons OnClick event for it to work reliably. Mine includes a backcolor change to add visual confirmation something changed. Also, I think it is worth you doing this and understanding it but personally after 4 developer lessons, VBA makes it much easier.
Ben Perry  @Reply  
       
5 months ago

Ben Perry  @Reply  
       
5 months ago

Ben Perry  @Reply  
       
5 months ago

Donald Blackwell  @Reply  
       
5 months ago
Amir

Replace the actual word "Toggle" in your macro with the control name of your toggle button then you should be okay
Amir Ouranus OP  @Reply  
      
5 months ago
Hi Ben!!!
That worked!!!
Thank you!!!
Ben Perry  @Reply  
       
5 months ago
You're welcome. I remember fighting that at first too.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 12:09:42 PM. PLT: 0s