Results 1 to 8 of 8
  1. #1
    Steve1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    4

    Using fSort procedure to aqvoid too many nested IIF conditions in a query

    I've created 2 fSort modules in a query to pull 2 different fields from a table and assign a unique name to each. Both modules look identical syntax-wise.

    This one works perfectly:
    Option Compare Database
    Option Explicit
    Public Function fSort1(district As String)
    Select Case district
    Case "NC", "SC"
    fSort1 = "NCSC"
    Case "TN/KY - E", "TN/KY - W"
    fSort1 = "TNKY"
    Case "FL - N", "FL - S"
    fSort1 = "FL"
    Case "AL", "MS", "LA"
    fSort1 = "ALMSLA"
    Case "GA - Out", "GA - Atl"
    fSort1 = "GA"
    End Select
    End Function


    This one stops after the first record:

    Option Compare Database
    Option Explicit
    Public Function fSort(ospcm As String)
    Select Case ospcm
    Case "NC EAST", "NC WEST"
    fSort = "NC"
    Case "SOUTH CAROLINA"
    fSort = "SC"


    Case "Georgia Atlanta"
    fSort = "GA - Atl"
    Case "GEORGIA OUTSTATE"
    fSort = "GA - Out"
    Case "ALABAMA FL', FL NOrth"
    fSort = "FL - N"
    Case "FL South"
    fSort = "FL - S"
    Case "ALABAMA"
    fSort = "AL"
    Case "MISSISSIPPI"
    fSort = "MS"
    Case "LOUISIANA"
    fSort = "LA"
    Case "kentucky e", "tn east"
    fSort = "TN/KY - E"
    Case "kentucky w", "tn west"
    fSort = "TN/KY - W"
    End Select
    End Function



    Thanks in advance,
    Steve1

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Steve,

    Is there a question here somewhere? Where would we use these?
    Welcome to the forum. Good to see the use of Option Explicit.

  3. #3
    Steve1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    4
    The question is why is the second only returning the first record??

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Did you test your code? Did you try calling your "function" from a loop situation?

    Shouldn't one call to a function only return 1 value?
    Please show us the code where you ran the function and it only returned the first record.

  5. #5
    Steve1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    4
    It's the second set of code in my thread.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Where is fSort function called from - query, textbox, VBA? How is the ospcm variable set? What is its value when the procedure fails? Does every record have a value in the relevant field?
    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
    Steve1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    4
    It's called from a procedure in a module. I figured it out though. The code was fine - the problem was that the field I was importing from Excel had embedded spaces in the data. Thanks.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848

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

Similar Threads

  1. Nested And/Or query
    By kagoodwin13 in forum Queries
    Replies: 2
    Last Post: 05-10-2012, 12:10 PM
  2. Replies: 5
    Last Post: 04-20-2012, 06:40 PM
  3. Nested SQL Query
    By springboardjg in forum Queries
    Replies: 5
    Last Post: 05-08-2011, 05:01 PM
  4. Replies: 6
    Last Post: 04-24-2010, 11:12 AM
  5. Query on multipl conditions.
    By Goldenbird in forum Queries
    Replies: 0
    Last Post: 06-28-2009, 11:45 PM

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