Results 1 to 7 of 7
  1. #1
    CodeLiftSleep is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    May 2017
    Posts
    48

    Question UDF in an IN statement not working properly in query

    I am not sure exactly what is going wrong here...I have a created query that runs upon loading and I need to pass in different values based on who is logging in...

    So I have a UDF that works fine when I am running it on a recordset, but does now work when I use it in the query...it returns nothing even though I check to make sure it is returning the proper values.



    Basically I have the following:

    WHERE ((t.JanSAM IN (strEmpArrVal())) with strEmpArrVal being the UDF returning a string of values which are formatted properly ('name1', 'name2', name3', etc...). Again, I am wondering why this works properly when I run an SQL statement against a recordset in code but not in the query with the same SQL statement.

    Does anyone know why this is not working properly? Can I simply update the QueryDef to take the string value itself once I get it?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    The query object will see the return from the UDF as simply a string of characters (including apostrophes and commas), not as a set of discrete values. LIKE and wildcard might be able to work.

    What is this query used for? If it is the RecordSource of a form or report, use the UDF to set Filter property. Or WHERE CONDITION of OpenForm/OpenReport.
    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
    CodeLiftSleep is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    May 2017
    Posts
    48
    Hmm...is it possible to feed the recordset to the query?

    It's being used when a manager logs in, it will bring up his report, which shows a list of all his employees and their accounts they are responsible for...

    the UDF returns his list of employees...the query is being used by the Report as the Source...

    What are my options here?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    A query object like:

    SELECT * FROM table WHERE ID IN (SELECT ID FROM datasource WHERE someCriteriaHere)

    How do you 'know' these are his employees? Is there a "SupvervisorID" field in Employees table or Departments table or something somewhere can apply filter: =[enter supervisor ID]?
    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.

  5. #5
    CodeLiftSleep is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    May 2017
    Posts
    48
    Quote Originally Posted by June7 View Post
    A query object like:

    SELECT * FROM table WHERE ID IN (SELECT ID FROM datasource WHERE someCriteriaHere)

    How do you 'know' these are his employees? Is there a "SupvervisorID" field in Employees table or Departments table or something somewhere can apply filter: =[enter supervisor ID]?
    I get his user name via the Environ("usename") which gets checked against a table of managers---if he is found in there, I bring back his matching Id and set Manager privileges for the loggedUser. Then when I run the queries I check the employee table for any employee with a ManagerId of his(4 in this case) and bring back all the employees.

    Then I go into the accounts table and bring back all matching accounts with those employees responsible for them(57 records in this case) matching the employee name to the array using IN for all 12 months as I need to bring back all accounts that at any point in the past 12 months were assigned to them....

    I'm wondering I return all the accounts and then filter the report if that might be easier...can a filter accept an array of values?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Can you build a query that includes accounts and employees tables? Apply ManagerID filter to the field from Employees table?
    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.

  7. #7
    CodeLiftSleep is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    May 2017
    Posts
    48
    What I ended up doing was to create a temp table, download all of the accounts to that table and then run an INSERT INTO query to the main table and only put the accounts I needed in that table and then run the Report Query pulling back all records.

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

Similar Threads

  1. Replies: 28
    Last Post: 01-24-2018, 05:14 PM
  2. Selection Query not working properly
    By zipaway in forum Queries
    Replies: 9
    Last Post: 07-31-2014, 06:56 AM
  3. Update Query Not Working Properly !
    By hamxa7 in forum Queries
    Replies: 3
    Last Post: 09-20-2012, 04:58 PM
  4. Delete SQL statement not working properly
    By Alexandre Cote in forum Programming
    Replies: 3
    Last Post: 10-18-2010, 12:56 PM
  5. Query on chart not working properly!
    By Sim_ in forum Queries
    Replies: 0
    Last Post: 10-28-2009, 09:38 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