Results 1 to 8 of 8
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2016
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    Extract Everything to the right of the first numeric

    We have an excel workbook that is imported into access, but the Address field is always sent with some garbage data before the actual address. An example is


    Code:
    LYTZ Mason Mitch - Stand Alone1234 North Main St. Novia, MI 33333
    Is it possible in a query to extract only the
    Code:
    1234 North Main St. Novia, MI 33333

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,910
    Perhaps, if you created your own function.?

    However what is the 'garbage' has numbers in it?
    What happens if the address does not have numbers in it?

    I would be looking to get the data corrected BEFORE trying to import?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2016
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    I may have to create my own function.

    Unfortunately it doesn't appear that I'll be able to get the list in a good usable format when received (I've been trying for 3 months). I'll keep checking for how to locate a number in a string, and figure out how to parse from there. I'm sure LEFT or Mid or some combo can handle it, just have to find that int

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,910
    The simplest method would be to check each character for an ascii value of x to y where x = ascii(0) and y ascii(9). So loop for 1 to len(data) using Mid(data,loop,1)
    As soon as you find a value in that range, that gives you your starting position for a MID() and you can exit the loop.

    That will not work however for any of the caveats I mentioned previously?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2016
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Thanks for that tip!

    The address will always have numerics in it.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    You can use LIKE with "#" to determine if a character is a number. So in your UDF, which a query can call,

    loop from i = 1 to Len(string)
    Use Mid i to test for "#" and if it is True,
    use Mid(str,i) to return the rest.
    exit function

    Would you like to take a crack at it, or should I post a sample?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    I'm facing a reboot for Windows update so I will lose this notepad text (and I don't want to save it). Easier to just dump it here as a follow up to my last post.
    Against my nature, but here's a fish...
    Code:
    Function testNum(str As String) As String
    Dim i As Integer
    
    For i = 1 To Len(str)
       If Mid(str, i, 1) Like "#" Then
          test = Mid(str, i)
          Exit Function
       End If
    Next
    End Function
    RESULTS
    ?testnum ("LYTZ Mason Mitch - Stand Alone1234 North Main St. Novia, MI 33333")
    1234 North Main St. Novia, MI 33333
    Last edited by Micron; 02-04-2021 at 12:32 AM. Reason: code correction
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,910
    Quote Originally Posted by Micron View Post
    Against my nature, but here's a fish...


    Had to add some dummy text to post
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. numeric vs text
    By dfbrown000@tds.net in forum Access
    Replies: 3
    Last Post: 08-01-2016, 08:09 AM
  2. Testing for numeric
    By GraeagleBill in forum Queries
    Replies: 4
    Last Post: 02-23-2016, 07:59 AM
  3. Numeric overflow
    By slimjen in forum Forms
    Replies: 10
    Last Post: 10-19-2011, 01:26 PM
  4. Filtering for numeric value
    By Bear in forum Access
    Replies: 21
    Last Post: 07-31-2011, 05:08 PM
  5. Numeric vs. Text
    By Niki in forum Access
    Replies: 4
    Last Post: 06-10-2011, 01:28 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