Results 1 to 13 of 13
  1. #1
    jbarrum is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Apr 2009
    Location
    Houston, Tx
    Posts
    164

    Question on filtering a form


    Is it possible to create a form that displays all records in a query but allows the user(viewer) of the form to filter the records based on one or more colomns in the view?

  2. #2
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    Yes, either modify the forms recordsource, or better yet, set the form's "FilterOn" property to Yes, and the form's "Filter" property to your filter criteria.

  3. #3
    jbarrum is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Apr 2009
    Location
    Houston, Tx
    Posts
    164
    Good morning,

    thanks for sharing. I am not sure I am clear on how your 2nd solution would work. What do I put in the "Filter" property. the field name that I want to filter on? I tried this and nothing happen when I ran the report.

  4. #4
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    The filter property is set to exactly the same thing that would be in the WHERE clause of a SQL query but without the word "WHERE", e.g
    Code:
    Me.Filter ="YourFilterFieldName=" integervalue ' for an integer value
    or
    Me.Filter ="YourFilterFieldName='" & textstring & "'" ' 
    for a text string 
    or
    Me.Filter ="YourFilterFieldName=#" adate "#" ' for a date
    or
    Me.Filter = "YourFilterFieldName=" & me.YourfilterfieldFormControlName ' 
    for a referenced value 
    Also, set
    Code:
    Me.FilterOn true 

  5. #5
    jbarrum is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Apr 2009
    Location
    Houston, Tx
    Posts
    164
    If I want to filter on last name and the field for last name is LName would the code from above look like the following:

    Me.Filter ="LName='" & textstring & "'" ' for a text string

    sorry, I know every little about VBA code. I am sure you coloar coding of the code has meaning but I am not familiar.

  6. #6
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    The color coding is added by this forum.

    Your Filter property is correct.

    Don't forget to set FilterOn=True

  7. #7
    jbarrum is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Apr 2009
    Location
    Houston, Tx
    Posts
    164
    I need help with one more thing then. Where do I add "Me.FilterOn=True"

  8. #8
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    Immediately before the "Me.Filter=..." line.

  9. #9
    jbarrum is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Apr 2009
    Location
    Houston, Tx
    Posts
    164
    Maybe I am confused as to where this previous code goes. I was putting it in the the field called "Filter" on the DATA tab of the form properties. Is that were it goes or does it go somewhere else?

  10. #10
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    If you adding the filter in the property window, use

    For the property "Filter"
    Code:
    "LName=" integervalue ' for an integer value
    or
    "LName='" & textstring & "'" ' 
    for a text string 
    or
    "LName=#" adate "#" ' for a date
    or
    "LName=" & me.YourfilterfieldFormControlName ' 
    for a referenced value 
    for the property FilterOn
    Code:
    Yes 
    I though that you were setting same following some event. Hardcoding the Filter and Filtefor properties works only for the specified value filter value, unless it's a referenced value.

  11. #11
    jbarrum is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Apr 2009
    Location
    Houston, Tx
    Posts
    164
    no, I do not want to hard code a filter value. I was hoping the form could be interactive and allow the user to type a value or select a value to filter on.

    anther words, when the user opens the form they can apply the filter themselves in some way.

  12. #12
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    Use
    FilterOn property
    Code:
    Yes 

    Filter property
    Code:
    "LName=" me.YourfilterfieldFormControlName 
    for a referencing a control on your form, probably a combo box

    Any time
    me.YourfilterfieldFormControlName changes, the form will display different data.

  13. #13
    jbarrum is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Apr 2009
    Location
    Houston, Tx
    Posts
    164
    let me try that

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

Similar Threads

  1. Filtering data
    By billybong in forum Access
    Replies: 1
    Last Post: 11-07-2009, 12:20 PM
  2. Filtering in a report
    By SIM_2009 in forum Reports
    Replies: 1
    Last Post: 10-06-2009, 04:22 AM
  3. Filtering my report
    By ldarley in forum Reports
    Replies: 1
    Last Post: 09-05-2008, 09:14 AM
  4. Replies: 0
    Last Post: 08-17-2008, 12:19 PM
  5. Automatic Filtering when Opening form
    By Karyn-2000 in forum Forms
    Replies: 1
    Last Post: 12-03-2005, 09:29 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