Results 1 to 10 of 10
  1. #1
    bobt9901 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    2

    passing *everything* criteria to query from form


    Hi All

    I am trying to pass variables to a query from a form. I have some drop downs to select the relevant criteria. I put the name of the control on the form into the criteria of the query. This works fine to a point.

    I cannot however give a wildcard. e.g. i can select from a 'level' drop down either level 1,level2,level3 but cannot select 'all'

    I would like to be able to either allow multiple values in the drop downs to add more criteria to the search query or add a 'all' to the combo


    Any ideas?

  2. #2
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    You best bet here is to 'assemble' the SQL you need as you need it ( I am making a slight assumption that this query feeds the same form..)

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Why not wildcard the parameter? If the combobox is left blank, that will equate to 'all'.

    The alternative is as R_Badger suggests. Use VBA code to assemble the filter string. Is the query used as the RecordSource for a report (or form)? Use the assembled string in the WHERE CONDITION argument of DoCmd.OpenReport (or OpenForm). If it is for the same form holding the search combos then use the string to set Filter property and set FilterOn property as needed to turn filter on and off.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    bobt9901 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    2
    hi

    i tried leaving the combo box blank but it did not seem to remove that criteria, it did not return anything.

  5. #5
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    Having slept on it, I had a thought.

    can you post the SQL from your query? If my thoughts are correct I should be able to help you.

  6. #6
    Subwind is offline Can Only Learn
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Location
    Portsmouth, UK
    Posts
    61
    I have used this code in alot of my query filters.

    Click image for larger version. 

Name:	imgQueryFilterExample.PNG 
Views:	18 
Size:	3.2 KB 
ID:	7829


    I then have an "Apply Filter" button which requeries the list box based on the filters.

    If left blank, this shows all records.

    Is this the sort of thing you are looking for?

    ~Matt

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Subwind, your code does not display in post. Is it an image you tried to attach?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Subwind is offline Can Only Learn
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Location
    Portsmouth, UK
    Posts
    61
    Quote Originally Posted by June7 View Post
    Subwind, your code does not display in post. Is it an image you tried to attach?
    It was an image, dropbox link. Does it show now?

    ~Matt

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Yes, it now shows.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    another option to try it its only one or two boxes you use like that is:

    like "*" & [forms]![frmcustomerlist]![txtcustomerfilter] & "*" or [forms]![frmcustomerlist]![txtcustomerfilter] is null.

    If however you plan on using this technique on more than one or two controls/fields then you are better off assembling the SQL on the form. I have a printout somewhere of the SQL of a query which had 6 controls like that... it ended up being 15 a4 pages long, the SQL needed for the most complex where criteria is less than 2 lines long if it is assembled on demand.

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

Similar Threads

  1. Passing Form Variable to Query
    By allenrickson in forum Reports
    Replies: 10
    Last Post: 06-27-2011, 07:33 PM
  2. Passing Multi Select string to Query criteria
    By oleBucky in forum Queries
    Replies: 4
    Last Post: 05-15-2011, 02:11 PM
  3. Passing form fields criteria to a Query
    By yosik20 in forum Queries
    Replies: 1
    Last Post: 05-12-2011, 04:24 AM
  4. Form not passing data to query
    By bobfin in forum Queries
    Replies: 13
    Last Post: 08-11-2010, 05:28 AM
  5. Passing Criteria to IN statement from Form
    By stephenaa5 in forum Queries
    Replies: 1
    Last Post: 10-09-2009, 04:02 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