Filter button

C

CY

I know this should be easy but for some reason I can't figure this out.

I need 2 buttons on a form that will filter the data. One button will show
all records that are "active" (or contain a "1" in the active field.

The other button should show all records that have something in the "Notes"
field. I can easily do either manually by right clicking and choose (in the
first case) filter by selection or (as in the second case) filter excluding
selection when on an empty notes field. But I can see this will be a
problem later once we start getting less active records and less fields
without notes.

How do I do this on a button so that the button will see "Filter ACtive
Records" and "Filter Accounts with Notes".

TIA

CY
 
J

Jeanette Cunningham

CY,
I am going to suggest you use an option group.
One option would be Show Active Records
the other option would be Show Accounts with Notes.

You use the after update event of the option group like this:
Select case NameOfOptionGroup
Case 1
'code here to filter the form to active records

Case 2
'code here to filter the form to accounts with notes
End Select


Jeanette Cunningham
 
C

CY

OK, but the cide is what i am asking for ;)
Jeanette Cunningham said:
CY,
I am going to suggest you use an option group.
One option would be Show Active Records
the other option would be Show Accounts with Notes.

You use the after update event of the option group like this:
Select case NameOfOptionGroup
Case 1
'code here to filter the form to active records

Case 2
'code here to filter the form to accounts with notes
End Select


Jeanette Cunningham
 
J

Jeanette Cunningham

Dim strFilter as String
Select case NameOfOptionGroup
Case 1
'code here to filter the form to active records

strFilter = "TableName.Active = 1"

Case 2
'code here to filter the form to accounts with notes
strFilter = "TableName.Notes Is Not Null"
End Select

If Len(strFilter) >0 Then
Me.Filter = strFilter
Me.FilterOn = True
Else
Me.FilterOn = False
End If

Replace NameOfOptionGroup, TableName with the name of your control, table,
and Active and Notes with the names of your fields.

Jeanette Cunningham
 
C

CY

Thank you for this...

Can't this be done as a macro that I can invoke from a button? I tried to
use the "Apply Filter" action but I was confused about what arguments to
use??
 
J

Jeanette Cunningham

OK. There is a detailed example of how to filter a form using a macro with a
command button in a form in the Northwind sample database.
To find Northwind, open Access, select Help | Sample Databases | Northwind
Sample Database

Have a look at the form called Customer Phone List
Have a look at the macro called Customer Phone List


Jeanette Cunningham
 
C

CY

Thank you :)
Jeanette Cunningham said:
OK. There is a detailed example of how to filter a form using a macro with
a command button in a form in the Northwind sample database.
To find Northwind, open Access, select Help | Sample Databases | Northwind
Sample Database

Have a look at the form called Customer Phone List
Have a look at the macro called Customer Phone List


Jeanette Cunningham
 
W

Werner Schendel

CY said:
I know this should be easy but for some reason I can't figure this out.

I need 2 buttons on a form that will filter the data. One button will
show all records that are "active" (or contain a "1" in the active field.

The other button should show all records that have something in the
"Notes" field. I can easily do either manually by right clicking and
choose (in the first case) filter by selection or (as in the second case)
filter excluding selection when on an empty notes field. But I can see
this will be a problem later once we start getting less active records and
less fields without notes.

How do I do this on a button so that the button will see "Filter ACtive
Records" and "Filter Accounts with Notes".

TIA

CY
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top