Results 1 to 14 of 14
  1. #1
    brs's Avatar
    brs is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    17

    filter subform with command button from within the subform

    hi,
    i have a subform with fields like bookname, publisher, category etc.
    i have comboboxes within the same subform which selects values; and a command button which is supposed to filter records corresponding to the combobox values.

    i have a code like -


    Me.Child2.Form.Filter = "[bookname]=" & [booknamecombo]
    Me.Child2.Form.FilterOn = True

    this obviously doesnt work as it filters from a command button in main form not subform. i want a code which works from within the subform. any ideas?

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    brs's Avatar
    brs is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    17
    looks promising. it'll take time to work out.
    thanks for quick response.

  4. #4
    brs's Avatar
    brs is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    17
    i typed -

    Me.Form.Filter = "[book name]=" & Me!BooknameCombo
    Me.Form.FilterOn = True

    it shows run-time error 3075 syntax error (missing operator) in query expression '[book name]= ComboboxValue'

    help

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    If the field is text try

    Me.Form.Filter = "[book name]='" & Me!BooknameCombo & "'"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    brs's Avatar
    brs is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    17
    does work !!! thanks a lot Paul.

    now how can i add wild card character to the syntax so that i can search for the book from anywhere in the field. i tried something like-

    Me.Form.Filter = "[book name]='" * " & Me!BooknameCombo & " * """"

    this doent work. also i need to know how can i add other fields with 'add' like
    Me.Form.Filter = "[book name]='" * " & Me!BooknameCombo & " * " and " * " & Me!BookAuthorCombo & " * "
    please help

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Try

    Me.Form.Filter = "[book name] Like '*" & Me!BooknameCombo & "*'"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    brs's Avatar
    brs is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    17
    book name and author filters individually but when i try to add 'and' and type -

    Me.Form.Filter = "[book name] Like '*" & Me!BooknameCombo & "*'" And "[Author] like '*" & Me!AuthorCombo & "'"

    this shows runtime error - 13 - type mismatch
    where am i getting wrong?

  9. #9
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Your missing a wildcard at the end of the code, it may be the error.

    Me.Form.Filter = "[book name] Like '*" & Me!BooknameCombo & "*'" And "[Author] like '*" & Me!AuthorCombo & "*'"

  10. #10
    brs's Avatar
    brs is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    17
    nope. it still doesnt work. besides i dont really need wildcard at the end.

    i double checked that filter on author works perfectly if applied individually. the error shows only with 'and'

  11. #11
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Try this :

    Me.Form.Filter = "[book name] Like '*" & Me!BooknameCombo & "*' and [Author] like '*" & me!AuthorCombo & "'"

  12. #12
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Ive tried above code on my database (just to make sure im not making a fool of myself) and it works for me.

  13. #13
    brs's Avatar
    brs is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    17
    well you were not making a fool of yourself. it does work!!
    thanks a lot

  14. #14
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Your welcome mate

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

Similar Threads

  1. Replies: 4
    Last Post: 10-08-2012, 05:33 PM
  2. Command button to populate subform
    By akhlaq768 in forum Forms
    Replies: 2
    Last Post: 02-07-2012, 04:57 AM
  3. Command Button Problem is Subform
    By Lupson2011 in forum Access
    Replies: 3
    Last Post: 08-25-2011, 08:39 AM
  4. Filter command not working for subform
    By yes sir in forum Access
    Replies: 15
    Last Post: 10-15-2010, 10:06 PM
  5. command button to filter a subform issue -
    By countdrako in forum Forms
    Replies: 1
    Last Post: 12-09-2005, 11:58 PM

Tags for this Thread

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