Results 1 to 5 of 5
  1. #1
    bmschaeffer is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    24

    Excel Formula Needed in Access

    I have a formula in excel that produces the text before the second "space" that I need to use in access.

    This is my excel formula:


    =IF((LEN(C6)-LEN(SUBSTITUTE(C6," ",""))<=1),C6,(LEFT(C6,FIND(" ",C6,FIND(" ",C6,1)+1)-1)))

    This is what I tried in access, but I am getting #Error:
    Traveler: IIf((Len([Vendor])-Len(Replace([Vendor]," ",""))<=1),[Vendor],(Left([Vendor],InStr(" ",[Vendor],InStr(" ",[Vendor],1)+1)-1)))

    Please help!

  2. #2
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Your issue is the syntax for the Instr Function. Look here for the proper syntax:

    http://www.techonthenet.com/access/f...ring/instr.php

    Alan

  3. #3
    bmschaeffer is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    24
    The first argument of the IIf function works fine if the string is 2 words. I am struggling with the FALSE argument of the IIf function. For a string with more than 2 words I need everything before the second space. I am only getting everything before the first space with this formula.

    Traveler: IIf((Len([Vendor1])-Len(Replace([Vendor1]," ",""))<=1),[Vendor1],(Left([Vendor1],(InStr(1,[Vendor1]," ")))))

  4. #4
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    You will have to add the Mid function to your formula to get the second space identified. Your starting position will be the formula for the first space plus 1. What I usually do with these type of comples expressions is put each part in a different field in the query and then join them with concatenation and then hide the helper fields or then rebuild the expression with the parts. A little tedious, but once complete a feeling of satisfaction.

    Look here
    http://www.techonthenet.com/access/f...string/mid.php

  5. #5
    bmschaeffer is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    24
    SOLVED IT! Thank you for your help

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

Similar Threads

  1. Replies: 5
    Last Post: 12-14-2011, 08:24 AM
  2. help needed to export a quarie to excel
    By cslr in forum Import/Export Data
    Replies: 2
    Last Post: 11-07-2011, 10:51 AM
  3. Replies: 1
    Last Post: 06-16-2010, 11:54 PM
  4. Replies: 0
    Last Post: 09-03-2009, 01:58 PM
  5. Max formula in Access
    By mohsin74 in forum Programming
    Replies: 2
    Last Post: 12-26-2006, 07:21 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