Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    wwalkerbout is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2012
    Location
    Los Angeles
    Posts
    15

    Question Extract Strings from a Dot Notation Field

    Greetings,

    I would like to construct one or more functions that will allow me to extract each string element from a dot notation populated field. An example of the content of such a field (perhaps named [Org_Structure]), would be:

    Organization.Division Name.0001 - Region Name.123456 - Area Name.A Rather Long Location Name

    In populating the [Org_Structure] field, I'll be able to strip out all special characters between the "." (dot) delimeters except the "-" (hyphen) character.

    So what I need to be able to do is then use a function to strip out each of the values between the dot notation delimeters into separate fields.

    I have a feeling that this can be done using the "instr" function in conjunction with perhaps the "left" function or some other combination, but I'm not sure what would be the best way to approach this so that I can easily create a separate function for each element to be extracted to a separate field.



    Can anyone help me figure out the best way to approach this?

    Any assistance would be most appreciated.

    Cheers,

    Wayne

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    Can use string manipulation functions such as Left, Mid, InStr. I think Split is one you will find very handy for your situation. It can only be used in VBA. Split will parse a string into a one-dimensional array as determined by designated delimiter. In your data the delimiter is dot.
    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
    wwalkerbout is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2012
    Location
    Los Angeles
    Posts
    15
    Hi June7,

    Thanks for the prompt response to my post. I am unfortunately limited to MS Access Functions. This is for use in a MS Project Server 2010 formula driven field, which is limited to using Functions (which happen to use the MS Access syntax). So I can't use VB.

    I had researched previously and gathered that I can use Functions such as Left, Mid and InStr to accomplish this. But I am not versed in MS Access Function development, so I was hoping someone would be able to provide me with an example of the code needed to target and extract any of the elements in this dot notation based field.

    As before, any information on samples of the actual code needed to extract these data elements would be much appreciated.

    Cheers,

    Wayne

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    I don't know anything about MS Project Server 2010. By 'formula driven field', do you mean a calculation in a query?

    If you can't use VBA, parsing that string into the 5 parts delimited by the dots is challenging, especially if the length of each part will vary from record to record. It will mean a treacherous nesting of Left/Right/Mid/InStr/InStrRev functions.

    Let's say x is the field with your example string and assume the length of each part is variable.

    Part1 is easy
    Left(x, InStr(x,".")-1)

    Part5 is easy
    Mid(x,InStrRev(x,".",Len(x))+1)

    Now it gets tricky.

    Part2
    Left(Mid(x,InStr(x,".")+1),Instr(Mid(x,InStr(x,"." )+1),".")-1)

    Part 3
    Left(Right(x,InStrRev(x,".",Len(x))),InStr(Right(x ,InStrRev(x,".",Len(x))),".")-1)

    Part4
    Mid(Left(x,InStrRev(x,".")-1),InStrRev(Left(x,InStrRev(x,".")-1),".")+1)

    I developed this code by using the VBA editor Immediate Window to test the constructs.
    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
    wwalkerbout is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2012
    Location
    Los Angeles
    Posts
    15
    Hi June7,

    I thought that this would be something that would be difficult to accomplish. You a right about a calculation in a query. Formula driven fields provide a very limited means of taking a field value and using just functions such as Left, Mid, InStr, etc... to manipulate field data.

    What you have provided is excellent! This is exactly what would have taken me many hours to figure out. I will test these out withing the Project Server 2010 formula driven field environment later today and let you know if it works.

    I really appreciate you taking the time to provide these examples for me. This is a huge help!

    Cheers,

    Wayne

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    Conceptually, it's not really difficult. Just getting the nesting correct is tricky. I have to build them piecemeal, inside to outside. After I get built, on second look I always wonder 'how in the world does that work!?!'

    Good Luck!
    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
    wwalkerbout is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2012
    Location
    Los Angeles
    Posts
    15
    Hi June7,

    I just finished testing your example code out within the Project Server 2010 environment and I ran into a problem. I found that the available string functions in Project Server 2010 are very limited. Below is the full list:

    Asc( string )
    Chr( charcode )
    Format( expression, format, firstdayofweek, firstweekofyear )
    InStr( start, string1, string2, compare )
    LCase( string )
    Left( string, length )
    Len( string )
    LTrim( string )
    Mid( string, start, length )
    Right( string, length )
    RTrim( string )
    Space( number )
    StrComp( string1, string2, compare )
    StrConv( string, conversion, LCID )
    String( number, character )
    Trim( string )
    UCase( string )

    So it appears that the 'InStrRev' Function is not available to me. As a result, only the first two examples worked. I guess this will get trickier as the levels get deeper too, right?

    When I looked into the details, I found that the organizational structure can be as a much as 8 levels deep. So, for instance, a more realistic example of the full structure would be:

    Corporate.Organization.Division Name.0001 - Region Name.Group Name.Market Name.123456 - Area Name.A Rather Long Location Name

    I think I could have worked out how to expand thing the code to cater for the additional levels, based on using the InStrRev Function that you had used in your examplee. But, looking at things again without that Function, I am struggling to work out if there is a way to parse all the way down to the 8 levels that I need.

    Are you able to suggest a way of doing that, when restricted to just the String Functions that I have listed above?

    If it is at all possible (even if the code becomes somewhat long), I'd love to be able to accomplish this. The difference with having this data parsed out and not having it is considerable. I'd have to define many additional fields without this ability.

    As before, any additional suggestions you might have would be most welcomed. I really have appreciated your previous assistance.

    Cheers,

    Wayne

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    I was struggling without the InStrRev function until I remembered about it.

    For instance, here is a different structure for Part3.
    Left(Mid(Mid(x,InStr(x,".")+1),Instr(Mid(x,InStr(x ,".")+1),".")+1),InStr(Mid(Mid(x,InStr(x,".")+1),I nStr(Mid(x,InStr(x,".")+1),".")+1),".")-1)

    On your own for the rest.

    Why is data in this format to begin with? Parsing strings is always harder than concatenating.

    Can't import to a table with Import wizard?
    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.

  9. #9
    wwalkerbout is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2012
    Location
    Los Angeles
    Posts
    15
    Hi June7,

    You're right. It is painful that this data is stored in this way. But it is all tied in to a built-in field called the RBS, which incorporates some security elements and therefore cannot be changed. It's painful, but unfortunately that's what I'm stuck with.

    However, as long as your code is, provided it works, it would save me a huge amount of effort in the long run.

    So I'll analyze what you have done and then work with that to see if I can get it working for the rest of the structure. If I can get it to work, it will really be worth it. I'll post my results.

    Again, I really do appreciate the effort you have put in to getting me this far. Perhaps there will be light at the end of the tunnel.

    Cheers,

    Wayne

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    I just hope you don't run into any string length limits. Part3 is already 144 characters, 255 might be max.
    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.

  11. #11
    wwalkerbout is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2012
    Location
    Los Angeles
    Posts
    15
    I probably will. But I'll try my best to be creative. Perhaps walking the string from each end to the middle will help reduce the number of bytes I need in the code.

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    At the risk of sounding pessimistic, that's what the InStrRev was needed for. You don't have that function available. Can only walk from the left.
    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.

  13. #13
    wwalkerbout is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2012
    Location
    Los Angeles
    Posts
    15
    Oh. Shows how much I know. I thought I might be able to use the left, right and mid functions in some way to do that. But then I wasn't even sure what they did. Maybe there isn't any light a the end of the tunnel after all.

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    Search Access Help or Google for specifics on string manipulation functions.
    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.

  15. #15
    wwalkerbout is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2012
    Location
    Los Angeles
    Posts
    15
    I'll do that. Probably won't get time to work on it until the weekend, but it'll certainly be worth my while if I can get this to work.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. how to search only CERTAIN strings in a field??
    By taimysho0 in forum Queries
    Replies: 1
    Last Post: 01-19-2012, 07:05 PM
  2. Extract certain values from field
    By tylerg11 in forum Programming
    Replies: 19
    Last Post: 09-23-2011, 03:27 PM
  3. Delete Specific Text Strings in a Field
    By JET in forum Queries
    Replies: 5
    Last Post: 08-25-2011, 03:33 PM
  4. Extract text from middle of a field
    By AccessNubie in forum Access
    Replies: 3
    Last Post: 11-02-2009, 01:13 PM
  5. How to extract names from 1 large field
    By Tepin in forum Access
    Replies: 1
    Last Post: 12-04-2006, 01:14 PM

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