Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2011
    Posts
    7

    Pass a Form Filter to a Query

    Dear Access Colleagues:

    I'm trying to pass the filter on a form (for example, one that's selected 25 of 100 records in the underlying table) to a query that, when run, will select the same 25 selected records. As near as I can tell, I want to take the "filter" property from the form and insert it into the filter property of the query. But so far, no luck on that. Any help will be appreciated.

    Thanks,


    Kent Sparks
    Berwyn, PA

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I believe you can do it opening another form or a report, using the wherecondition argument. I can't think of a way to filter a query. Most of us don't let users into tables or queries directly anyway.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Join Date
    Mar 2011
    Posts
    7
    Queries have a "Filter" property. I've put filters in it directly, but I really need to automate it so that the filtered datasset in the form is picked up and used by the query. End users wont touch this ... which is, in fact, why I need to do it this way.

    Basically, I need to know how one would set the Query filter property = to the Form filter property. I've figured out that I can't do this with functions and the like. I need code for it.

    Thanks

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The only possibility that comes to mind is using a DAO QueryDef to manipulate the query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188

    Re: Pass Filter to Query

    Here's some dao code that might work for you...I added it to a click event:

    Private Sub cmdFilter_Click()
    On Error Resume Next
    Dim strFilter As String
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim prp As DAO.Property

    strFilter = Me.Filter

    Set db = CurrentDb
    Set qdf = db.QueryDefs("qEmployers")

    With qdf

    Set prp = qdf.Properties("Filter")
    If Err Then
    Set prp = .CreateProperty("Filter", dbText, strFilter)
    .Properties.Append prp
    Else
    prp.Value = strFilter
    End If

    If strFilter = "" Then .Properties.Delete ("Filter")

    End With

    End Sub

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

Similar Threads

  1. Pass Subform filter to subform in report
    By camftm in forum Programming
    Replies: 16
    Last Post: 07-19-2011, 07:12 AM
  2. Pass subform filter to a report
    By dinorbaccess in forum Reports
    Replies: 3
    Last Post: 01-10-2011, 05:34 PM
  3. Pass a value from a query to a form
    By cwwaicw311 in forum Forms
    Replies: 22
    Last Post: 03-22-2010, 10:21 AM
  4. Pass a Parameter From a form to a Query
    By DDillesha in forum Forms
    Replies: 1
    Last Post: 10-28-2009, 12:49 PM
  5. Form Based Query/Filter
    By Micon in forum Access
    Replies: 0
    Last Post: 11-07-2008, 09:25 AM

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