Results 1 to 3 of 3
  1. #1
    Sparky is offline Novice
    Windows 7 Access 2003
    Join Date
    Nov 2010
    Posts
    6

    Using a function as a criteris in a query

    Not sure if this belongs in programming or queries, but....

    The following query runs exactly as I want it to.

    The query:


    SELECT Query9.ID, Query9.BusinessGroup, IIf(forms!TestQ!Text0="All Business Groups","1",0)+IIf(Forms!TestQ!Text0="HR",2,0)+IIf (Forms!TestQ!Text0="Manufacturing",3,0) AS AA, Query9.FunctionID, Query9.FunctionName, Query9.FunctionType, Query9.XX, Query9.BB, IIf([BB]=" 'HR' Or 'Manufacturing'","Equal","Not") AS c
    FROM Query9
    WHERE (((Query9.BusinessGroup)='HR' Or (Query9.BusinessGroup)='Manufacturing'));

    The Criteria in the criteria row of the query design grid:

    'HR' Or 'Manufacturing'

    Then, I have a function that cycles through a listbox and gets essentially the same string. The function is called GetCriteria(). I have a debug.print statement in the function to see what the final string is. Final string is:

    'HR' Or 'Manufacturing'

    When I use the function GetCriteria() in the criteria row for field BusinessGroup, I get no records. Following is the SQL for when the GetCriteria() function is used.

    SELECT Query9.ID, Query9.BusinessGroup, IIf(forms!TestQ!Text0="All Business Groups","1",0)+IIf(Forms!TestQ!Text0="HR",2,0)+IIf (Forms!TestQ!Text0="Manufacturing",3,0) AS AA, Query9.FunctionID, Query9.FunctionName, Query9.FunctionType, Query9.XX, Query9.BB, IIf([BB]=" 'HR' Or 'Manufacturing'","Equal","Not") AS c
    FROM Query9
    WHERE (((Query9.BusinessGroup)=GetCriteria()));

    Can someone suggest why I don’t get any records with the second Select statement and I get all the records I expect with the first Select statement?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,597
    I tried your idea and it won't work. I think would have to modify the query definition with QueryDef

    I don't like to use dynamic parameters in queries. I prefer to use WHERE CONDITION of DoCmd.OpenForm (or OpenReport).

    Review http://allenbrowne.com/ser-50.html
    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.

  3. #3
    Sparky is offline Novice
    Windows 7 Access 2003
    Join Date
    Nov 2010
    Posts
    6

    Thanks

    Quote Originally Posted by June7 View Post
    I tried your idea and it won't work. I think would have to modify the query definition with QueryDef

    I don't like to use dynamic parameters in queries. I prefer to use WHERE CONDITION of DoCmd.OpenForm (or OpenReport).

    Review http://allenbrowne.com/ser-50.html
    Good idea, I'll try this.

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

Similar Threads

  1. Count Function in query
    By tjstromquist in forum Queries
    Replies: 1
    Last Post: 04-03-2012, 10:40 AM
  2. NZ Function in Access Query
    By Rosier75 in forum Queries
    Replies: 2
    Last Post: 11-02-2011, 06:14 AM
  3. Help W/A Query Using an Inverse Function
    By jmaitri in forum Queries
    Replies: 2
    Last Post: 04-10-2011, 05:53 AM
  4. Replies: 4
    Last Post: 11-19-2010, 07:21 PM
  5. Query using count function
    By wasim_sono in forum Queries
    Replies: 0
    Last Post: 11-28-2007, 03:16 AM

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