473,386 Members | 1,819 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,386 software developers and data experts.

Multiple filter command buttons on a form

55
Working in Access 2000... I have a form with records for every employee. I'd like to create two command buttons so a user can filter the form for either 'only current' or 'only former' employees. I applied the first filter ([Termination Date] Is Null) and created the first 'apply filter' command button (using the wizard), then cleared the filter, applied the second filter ([Termination Date] Is Not Null), and created the second command button. It changed the first button to apply the same filter as the second button.

How do I create two different filter options on the same form? Using the wizard, the event procedure that was created is:

Private Sub CmdCurrent_Click()
On Error GoTo Err_CmdCurrent_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70

Exit_CmdCurrent_Click:
Exit Sub

Err_CmdCurrent_Click:
MsgBox Err.Description
Resume Exit_CmdCurrent_Click

End Sub

I don't understand enough of this to know how to change it.

Any ideas?

Angi
Jan 29 '08 #1
3 9013
JustJim
407 Expert 256MB
Working in Access 2000... I have a form with records for every employee. I'd like to create two command buttons so a user can filter the form for either 'only current' or 'only former' employees. I applied the first filter ([Termination Date] Is Null) and created the first 'apply filter' command button (using the wizard), then cleared the filter, applied the second filter ([Termination Date] Is Not Null), and created the second command button. It changed the first button to apply the same filter as the second button.

How do I create two different filter options on the same form? Using the wizard, the event procedure that was created is:

Private Sub CmdCurrent_Click()
On Error GoTo Err_CmdCurrent_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70

Exit_CmdCurrent_Click:
Exit Sub

Err_CmdCurrent_Click:
MsgBox Err.Description
Resume Exit_CmdCurrent_Click

End Sub

I don't understand enough of this to know how to change it.

Any ideas?

Angi
Hi Angi,

First of all, don't worry about not understanding the DoCmd.DoMenuItem command. Nobody understands that unless they have all 5 previous versions of Access installed and running and they go to the menu bars and count the steps!

What I think you need is an option group with two toggle buttons (the ones where when one is pressed, the other pops up)

In the option group's AfterUpdate event you need something like (I'm just typing here, the code hasn't been checked)
Expand|Select|Wrap|Line Numbers
  1. Private Sub ToggleOne_OnClick()
  2.  
  3. If Me.ToggleOne = True Then
  4.      Me.Filter = "[Termination Date] Is Null"
  5.      Me.FilterOn = True
  6. Else
  7.      Me.Filter = "[Termination Date] Is Not Null"
  8.      Me.FilterOn = True
  9. End If
  10.  
  11. End Sub
The actual filter wording may need some work, I seem to remember that it should be like an SQL WHERE clause without the word "Where"

Good Luck

Jim

Ps if you need a third option (all employees) you'll need a third option button, ElseIf testing (or possibly a Select Case statement) and Me.Filter = ""
Jan 30 '08 #2
angi35
55
Thanks, Jim. I got it to work. For the record, here's what it looks like. (Case 2 is current, 3 is former, and 1 is all.)

Private Sub Frame107_AfterUpdate()

Select Case Frame107

Case 2
Me.Filter = "[Termination Date] Is Null"
Me.FilterOn = True

Case 3
Me.Filter = "[Termination Date] Is Not Null"
Me.FilterOn = True

Case 1
Me.FilterOn = False

End Select


End Sub

Angi
Feb 1 '08 #3
JustJim
407 Expert 256MB
Thanks, Jim. I got it to work. For the record, here's what it looks like. (Case 2 is current, 3 is former, and 1 is all.)

Private Sub Frame107_AfterUpdate()

Select Case Frame107

Case 2
Me.Filter = "[Termination Date] Is Null"
Me.FilterOn = True

Case 3
Me.Filter = "[Termination Date] Is Not Null"
Me.FilterOn = True

Case 1
Me.FilterOn = False

End Select


End Sub

Angi
Good work.

Jim
Edited to add more characters (stupid 20 character limit)
Feb 2 '08 #4

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

Similar topics

1
by: jeffgeorge | last post by:
Hi all. Trying to move Filter By Selection, Filter By Form, and Apply/Remove Filter directly into my form. No luck. Is there anyway to move them into the header of the form or, as another...
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...
6
by: Ralph2 | last post by:
Some time ago with a lot of help from this group I made a reasonably successful database to keep track of our shop drawings. However the searching mechanism is too complicated for the occasional...
1
by: lorirobn | last post by:
Hi, I have a report that works just fine. Now I would like to add the capability to choose selection criteria to limit what is displayed. I created several reports that do this, but they used...
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...
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...
1
by: AccessNewbie | last post by:
Hello: I have a form (frmMain) that I have included a subform (frmSubForm) on. What I need on the MAIN form are command buttons that will filter the information on the SUBFORM. It is very...
1
by: eHaak | last post by:
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. ...
5
aas4mis
by: aas4mis | last post by:
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
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
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...

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.