Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    kathi2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    42

    Filter a Form with a form

    I have a form that sets the filter parameters for a query. That works great.



    I want the form to filter the form that is based on that query.

    the form I want for the results to show in is HDStock.

    The form that ask for the criteria is HDSearch.

    Right not I have HDStock set with the OnOpen FilterMe!Filter = filterString
    Me!Filter = "cboSize = " & Forms![HDSearch]![cboSize] & "And cboPCD=" & "'"
    Me!Filter = "cboPCD = " & Forms![HDSearch]![cboPCD] & "And cboOffset=" & "'"
    Me!Filter = "cboOffset = " & Forms![HDSearch]![cboOffset] & "And cboColor=" & "'"
    Me!Filter = "cboColor = " & Forms![HDSearch]![cboColor]

    I get a run-time error '2465': HDSearch can't find the field 'Filter' referred to in you expression and the query pops up

    Please help.

  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,641
    Try

    Me.Filter

    You might also need to put a space before the word "And..."
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    kathi2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    42
    Did that
    Now I get Run-Time '3075':
    Syntax error in string query expression 'cboSize = 18 And cboPCD=".

  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,641
    You realize that each of those lines replaces the previous, so you're never providing a complete string? It appears you want this type of thing (presuming size is numeric and PCD is text):

    Me!Filter = "cboSize = " & Forms![HDSearch]![cboSize] & " And cboPCD='" & Forms![HDSearch]![cboPCD] & "'"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    kathi2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    42
    Okay that makes sense I did not think about that.

    So I have changed it to one line of code, but still getting a syntax error

    Me!Filter = "cboSize = " & Forms![HDSearch]![cboSize] & " And cboPCD='" & Forms![HDSearch]![cboPCD] & "And cboOffset='" & Forms![HDSearch]![cboOffset] & "And cboColor='" & Forms![HDSearch]![cboColor]

    Run-Time 2465
    Size is Numeric
    The other 3 are text

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    You're not closing off the single quotes around the values, and you're not putting a space in front of the "And". Try

    Me.Filter = "cboSize = " & Forms![HDSearch]![cboSize] & " And cboPCD='" & Forms![HDSearch]![cboPCD] & "' And cboOffset='" & Forms![HDSearch]![cboOffset] & "' And cboColor='" & Forms![HDSearch]![cboColor] & "'"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    kathi2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    42
    Well at least the form opened this time, but nothing was filtered. All records showed up

  8. #8
    kathi2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    42
    Is it possible to be a mistake on the HDSearch form.

    Here is the code for that

    Private Sub cmdCancel_Click()
    DoCmd.Close acForm, "HDSearch"
    End Sub

    Private Sub cmdOK_Click()
    DoCmd.OpenQuery "HDComplete", acViewNormal, acEdit
    DoCmd.OpenForm "HDStock"
    End Sub

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Add this line right after the above:

    Debug.Print Me.Filter

    which will print out the finished filter to the VBA Immediate window. Does it look correct? Or can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    kathi2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    42
    Did that and nothing happened

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Nothing will "happen", other than the text being sent to the Immediate window. See here if you're unfamiliar with where that is:

    http://www.baldyweb.com/ImmediateWindow.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    kathi2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    42
    Seriously. I did not get another window. I tried again an no other window popped up.

    db is to big for on here, currently I am able to use the database and running my inventory from it, so it is very large.

    Owner wants me to dumb it down so everyone can use it, and not sure I can do that, but trying

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    No window will pop up. It should populate the Immediate window within the VBA editor, as pictured. Just minimize the VBA editor when you run the code, and then go check that window. If that window isn't already appearing in the VBA editor, click on View/Immediate Window.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    kathi2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    42
    ok Got it:
    cboSize = 18 And cboPCD='5:114.3' And cboOffset='Mid' And cboColor='Black'


    cboSize = 18 And cboPCD='5:114.3' And cboOffset='Mid' And cboColor='Black'

    cboSize = 18 And cboPCD='5:114.3' And cboOffset='Mid' And cboColor='Black'

    cboSize = 18 And cboPCD='5:114.3' And cboOffset='Mid' And cboColor='Black'

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Syntax-wise that looks correct for the data types you mentioned. Are those the field names in the table? They look more like combo box names.

    Wait a minute, I've had a "duh" moment. After the line setting the filter you need:

    Me.FilterOn = True

    to actually apply the filter.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 11-25-2013, 10:56 AM
  2. Replies: 2
    Last Post: 08-18-2011, 10:20 PM
  3. LogIn Form to filter Main Form
    By ggs in forum Forms
    Replies: 5
    Last Post: 07-12-2011, 04:27 AM
  4. form filter using form text box value
    By NDBCaccess in forum Access
    Replies: 1
    Last Post: 10-28-2010, 09:23 PM
  5. launching form with filter from other form
    By iankerry in forum Programming
    Replies: 4
    Last Post: 01-19-2010, 11:05 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