refresh current form with filtered records

abdoudiaw

Registered User.
Local time
Yesterday, 20:32
Joined
Sep 13, 2013
Messages
15
Hi,
Access beginner.
I have a form that displays records from a table.
When opened it displays all records (no selection yet).
I put would like to put 2 buttons to filter records (Male/Female).
I'm thinking of 2 possible options:
1-on click run a script that will close current form, then reopen it with selection criteria
2-directly apply a filter on the current form that would automatically refresh itself with the right records
Another (heavy, inelegant?) solution would be to create duplicates of this form. they would be loaded from separate queries that select the right records in either choice.
Thanks for any help including the VBA code.
 
Here's something I've done this before using an Option Group rather than multiple Command Buttons. This opens the Form unfiltered, then offers the user the ability to filter by Male, Female or (once again) All.

  1. Place an Option Group on your Form
  2. When the Wizard comes up, enter All, Male, Female into the Labels, in that order
  3. Rename the Option Group as optSortForm
Now, in the optSortForm's OnClick event:

Code:
Private Sub optSortForm_Click()
 
 Select Case optSortForm
 
  Case 1
    Me.FilterOn = False
  Case 2
    Me.Filter = "[Gender] = 'Male'"
    Me.FilterOn = True
  Case 3
   Me.Filter = "[Gender] = 'Female'"
   Me.FilterOn = True
 End Select

End Sub

Then, to let users know the original Sort (or lack of one, really)

Code:
Private Sub Form_Load()
 Me.optSortForm = 1
End Sub

Linq ;0)>
 
Last edited:

Users who are viewing this thread

Back
Top Bottom