Results 1 to 6 of 6
  1. #1
    StGermain is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    20

    Create a button to apply select query to a form? Also 2nd button to "remove" the query filtering?

    Hello. Sorry for the beginners question.




    I have a "Contacts Query" which selects certain records.

    I would like to create a button on my "Contacts" form that will apply the "Contacts Query" as a filter . . . and only show those few records that meet the "Contacts Query" criteria.

    What's the easiest way to do this?


    Then another button to "CLEAR QUERY" . . . when clicked, it will remove the query filtering . . . and once again show ALL the records.

    Thanks

  2. #2
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Not really enough info...
    Where does the "Contacts Query" criteria come from?


    I usually have code to set the form filter and to remove the filter.
    See Search criteria
    Code is here

    Maybe you would post your dB?

  3. #3
    StGermain is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    20
    Thanks for your help.

    I am using the generic, simple "Contacts" database supplied with Office 365 Access.

    I need a super-simple solution (NOT fancy code at the 'expert' level). I am not expert like you.

    TABLE = Contacts
    QUERY = Contacts Query (gets data from the Contacts table)
    FORM = Contact (gets data from Contacts table)

    All I need is some kind of easy FILTER ... maybe a macro? ... here is screen shot . .

    Click image for larger version. 

Name:	Contacts Query.jpg 
Views:	16 
Size:	140.5 KB 
ID:	44632

  4. #4
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Quote Originally Posted by StGermain View Post
    Hello. Sorry for the beginners question.


    I have a "Contacts Query" which selects certain records.

    I would like to create a button on my "Contacts" form that will apply the "Contacts Query" as a filter . . . and only show those few records that meet the "Contacts Query" criteria.

    What's the easiest way to do this?


    Then another button to "CLEAR QUERY" . . . when clicked, it will remove the query filtering . . . and once again show ALL the records.

    Thanks
    Hi!

    In Click event of "AddFilter" button:
    Code:
    Me.RecordSource="qryContacts"
    In Click event of "RemoveFilter" button:
    Code:
    Me.RecordSource="tblContacts"
    To code the Click event of a button, in design view, right click on the button and choose "Build Event...". Paste the lines of code above between Sub and End Sub of each relevant click event procedure.
    Last edited by accesstos; 03-16-2021 at 05:24 AM. Reason: spelling

  5. #5
    StGermain is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    20
    That works great!

    Thanks so much.

    Very clever!

  6. #6
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    You are welcome!

    Good luck with your project,
    John

    Edit: You could use a checkbox in place of buttons, with the code below for its AfterUpdate event:
    Code:
    Private Sub chkFilter_AfterUpdate()
        If Me.chkFilter Then
            Me.RecordSource = "qryContacts"
        Else
            Me.RecordSource = "tblContacts"
        End If
    End Sub
    where chkFilter the name of the checkbox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 04-08-2018, 08:18 AM
  2. Replies: 4
    Last Post: 08-05-2017, 12:33 AM
  3. Replies: 4
    Last Post: 07-17-2015, 09:11 PM
  4. Replies: 1
    Last Post: 01-16-2014, 12:33 PM
  5. Replies: 0
    Last Post: 01-11-2012, 12:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums