Results 1 to 3 of 3
  1. #1
    Ada01 is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    8

    Search for unique sting in Select Query

    I have a list of accounts that are formatted in the following manner

    790DDD.AAAA


    790DDDDDD.AAAA
    790DDD.AAAA.SubAcct
    790DDDDDD.AAAA.SubAcct

    790 is a fixed entity code and is the same on all account strings. All accounts have a "Department" (D) but the department is variable in length. All Accounts have and "Account" (A) and all accounts start with A and have a four digit number. Some accounts have a SubAccount (SA) and some do not.

    What I need to be able to do in a query is say (as I can in Excel):

    Code:
    IFERROR(IF(SEARCH(".****.","account number"),"SA"&RIGHT("account number",4),""),"NOSUBACCT")
    How can this be done. I have been able to isolate the records that meet this criteria in a separate query using the Criteria: "*.####.*" Can i use this query to isolate records in my final desired query?

    I have attached sample data and the solution i used in Excel. In access i have solved all sections of the account using the InStr(), but the SubAccount issue alludes me.

    Thanks
    Attached Files Attached Files

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    So all you're looking to do is to bring up a list of sub accounts if there are any and if there aren't any sub accounts put in the label 'NoSubAcct'? Your example only has 1 sub account per account, is that correct? or can an account have multiple sub accounts? The answer depends on the original data.

    To get the label you can do something like

    SubAccount: iif(instr(SubLedger, ".") <> instrrev(subledger, "."), right(subledger, len(subledger) - instrrev(subledger, "-") + 1), "NoSubAcct")

  3. #3
    Ada01 is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    8
    What I am looking to accomplish is to return the subaccount string from the "subLedger" field if the criteria exists to do so. All i have to go on is if the string of .####. exists. There can be only one sub-account per complete account number.

    When i apply your solution it returns the entire field, rather than the right four characters, but i think that is adjustable if I can following the functions.

    Less elegant and problematic if there is a data entry issue somehow:

    Code:
    SubAccount: IIf(Len([SubLedger])-Len(Replace([SubLedger],".",""))=2,"SA" & Right([SubLedger],4),"NOSUBACCOUNT")

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

Similar Threads

  1. Replies: 1
    Last Post: 10-29-2014, 10:23 AM
  2. Search using a multi select listbox
    By noobaccess in forum Access
    Replies: 13
    Last Post: 12-04-2012, 07:06 AM
  3. Replies: 2
    Last Post: 11-11-2012, 09:02 PM
  4. Multi select search
    By simba in forum Access
    Replies: 2
    Last Post: 08-22-2011, 08:28 AM
  5. Replies: 4
    Last Post: 03-17-2011, 06:17 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