Results 1 to 5 of 5
  1. #1
    Zukster is offline Novice
    Windows 98/ME Access 2003
    Join Date
    Aug 2009
    Posts
    15

    split text field

    I have a field with codes such as abc1, ab23, mad4 etc.



    I want to run a query that will split the field and give me the last # off of each code. Is there a formula to do this?

    thanks!

  2. #2
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    Will the string always be a block of text followed by a number?

    A8CB34 - Never, occasionally, rarely

    If you work on the pretext that it may happen what you need is the following function


    Code:
     
    Public Function GrabNumber(AnyString As String) As Integer
    
    'Test for a number as the last character
    If IsNumeric(Right(AnyString, 1)) = False Then
       GrabNumber = 0
       Exit Function
    End If
    For X = 1 To Len(AnyString)
    
    'Read string from right to left until a digit is encountered
     If IsNumeric(Mid(AnyString, Len(AnyString) - X, 1)) = False Then
        GrabNumber = Right(AnyString, X)
        Exit For
     End If
    Next
     
    End Function
    Then in your query

    AliasName:GrabNumber([<<YourFieldNameHere>>])

    David

  3. #3
    Zukster is offline Novice
    Windows 98/ME Access 2003
    Join Date
    Aug 2009
    Posts
    15
    The last field is ALWAYS a number. But sometimes there are other numbers in the field. Can I still use the above code?

  4. #4
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    The code I have supplied reads from right to left until it reaches a character that is not a numeric digit, such as any letter of the alphabet. At that point is returns the string of numbers found as an integer.


    Code

    ABC123 would return 123
    AB12C789 would return 789
    ABC5D would return 0
    123ABC would return 0

    David

  5. #5
    expling is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    1
    Hello,
    I want to split text from a field as follow:

    red star becomes "red" -> "star"
    red hot chilli becomes "red" -> "hot"; "hot" -> "chilli"
    the green house effect becomes "the" -> "green"; "green" -> "house"; "house" -> "effect"

    All the symbols like "->; are in the result field.

    Anyone know how to do this?
    Thanks
    exp

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

Similar Threads

  1. Split uneven text field
    By swaroop1012 in forum Queries
    Replies: 1
    Last Post: 09-11-2009, 07:42 AM
  2. Finding highest value in a text field
    By cdominguez in forum Queries
    Replies: 3
    Last Post: 06-02-2009, 09:39 AM
  3. Split text field into two text fields
    By Grant in forum Access
    Replies: 6
    Last Post: 01-31-2008, 05:52 AM
  4. Quick way to stuff field names into text field
    By kfinpgh in forum Programming
    Replies: 0
    Last Post: 01-04-2007, 01:13 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