Results 1 to 6 of 6
  1. #1
    gjennings1 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2011
    Posts
    3

    Query Question


    I am stumped on trying to create a query. This may be a juvenile question but I am trying to create a query from data out of a table. In this query I am wanting to return the original value if the cell does not contain a "/". Otherwise if it does contain a "/" I want to remove it and everything behind it. Any help will be greatly appreciated.

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Does the "/" always appear in the same Position in the string in that field?

  3. #3
    gjennings1 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2011
    Posts
    3
    It's not always in the same position.

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    I created a Text Field in a table and put this in one row:
    asdl/as345
    In the other rows, I didn't have any occurrences of "/".

    Then I created a Query and put this in a new field in design view:
    Code:
     
    Search_String: IIf(InStr(1,[Test],"/")=0,[Test],Left([Test],(InStr(1,[Test],"/")-1)))
    When I ran the query, it gave me "asdl" from the row with the ? in it - and all the other rows unchanged.

    Hope this helps!

    If you haven't used the IIf functoin, here's how it works (in this case):

    IIf(InStr(1,[Test],"/")=0, [Test], Left([Test],(InStr(1,[Test],"/")-1)))

    If there isn't a "/" then use the value in [Test] otherwise use All characters to the left of the "/"

  5. #5
    gjennings1 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2011
    Posts
    3
    I used the IIF function as you have said and it worked except I have some fields that are blank and I get #Error for those.

  6. #6
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Are your fields 'Blank' - or are they 'Null'?

    What would you like to see when there is a blank or null?

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

Similar Threads

  1. Query question/help
    By 9944pdx in forum Queries
    Replies: 4
    Last Post: 12-12-2017, 08:13 PM
  2. vba query question
    By jscriptor09 in forum Programming
    Replies: 2
    Last Post: 10-08-2011, 07:22 PM
  3. Query Question
    By Guiseppe in forum Queries
    Replies: 5
    Last Post: 03-23-2010, 04:32 PM
  4. Query with a question
    By sagit3 in forum Queries
    Replies: 0
    Last Post: 06-11-2009, 07:10 AM
  5. Query Question
    By blewis in forum Queries
    Replies: 0
    Last Post: 04-16-2009, 01:37 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