Results 1 to 15 of 15
  1. #1
    mlrucci is offline Competent Performer
    Windows 7 64bit Office 365
    Join Date
    Apr 2018
    Posts
    202

    Removing numeric and alpha from

    Good morning, I am attempting to update a table, preference is an update qry, by removing the numbers and _ from a table field. I am struggling with trying to remove "_", numeric and alpha at the end. In other words, from the numeric to the end needs to be removed (including the preceding "_". The data is inconsistent and struggling with trying to make this work, Can't do a left or right because of the inconsistency in the data. Any Ideas?

    Original:
    URDNKRECREM_JMA_11162021
    URASNRCRSVC_11162021B


    BPIN_NRSVEN_BK_11022021
    URASNRCRSVC_11022021_actionable


    Modified:
    URDNKRECREM_JMA
    URASNRCRSVC
    BPIN_NRSVEN_BK
    URASNRCRSVC

    Thank you in advance for your assistance

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Use instrrev() and left functions?
    Hmm that will not process your last entry.

    Perhaps split() inside your own function?
    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
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Is this the same issue as here but just a different character now?

    https://www.accessforums.net/showthr...160#post488160
    Need to delete all preceding 0s, delete anthing after the second "-" and removed the "-" in the middle.

    You'll need a function that loops over every character until it encounters a number, then get the string using Left and the number that the loop generates.
    EDIT can you adapt this one that I wrote for your other issue (but didn't post because you didn't answer my question(s).
    Code:
    Function mlrucci(strIn As String) As String
    Dim strOut As String
    Dim i As Integer
    
    '0871900602-601116-7-1
    'delete all leading 0's and anthing after the second "-". Remove the "-" in the middle.
    'End result should be: 871900602601116
    i = 1
    strOut = Left(strIn, InStr(InStr(strIn, "-") + 1, strIn, "-") - 1)
    Do While Mid(strOut, i, 1) = "0"
       i = i + 1
    Loop
    
    mlrucci = Mid(strOut, i)
    'Debug.Print mlrucci
    
    End Function
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    mlrucci is offline Competent Performer
    Windows 7 64bit Office 365
    Join Date
    Apr 2018
    Posts
    202
    Micron, yes and no, same issues but dealing with more inconsistencies. The other had no deviation in the layout of the data.

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    if all the numbers start with 1 then this would would

    ?left("URASNRCRSVC_11022021_actionable",instrrev(" URASNRCRSVC_11022021_actionable","_1")-1)
    URASNRCRSVC

  6. #6
    mlrucci is offline Competent Performer
    Windows 7 64bit Office 365
    Join Date
    Apr 2018
    Posts
    202
    Ajax, unfortunately, the numbers change every month. I used that code originally, but there are times that it doesn't work because of that variable every month.

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Maybe have a look at this sample using a custom VBA function (just copy it into a standard module).

    Cheers,
    Vlad
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Well, this is what I came up with
    Code:
    Function mrlucciVar(strIn As String) As String
    Dim strOut As String
    Dim i As Integer
    
    i = 1
    Do While Not IsNumeric(Mid(strIn, i, 1))
       strOut = Left(strIn, i)
       i = i + 1
    Loop
    mrlucciVar = Left(strOut, Len(strOut) - 1)
    'Debug.Print mrlucciVar
    
    End Function
    Last edited by Micron; 12-30-2021 at 01:55 PM. 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.

  9. #9
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    I used the one in here then a left with instr. It is a handy function to have as you can use it in many ways (ToNumber, OnlyNumber, FromNumber):
    https://techjogging.com/extract-numb...cessexcel.html
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  10. #10
    mlrucci is offline Competent Performer
    Windows 7 64bit Office 365
    Join Date
    Apr 2018
    Posts
    202
    Gicu, Thank you for the db example. I attempted to use the example and it works great sometimes. I am not sure what I am missing, but it seems that when I attempt to link/ or use relationship with the PCNID, it crashes and gives run-time error 13, type mismatch. I am including a stripped-down version of what I am working with. The db is based on importing information from excel, so pardon my naming conventions as they are not accurate as to allow import. Ideas?


    ExampleDB_ExtractNumber.zip

  11. #11
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    The error is caused by all the empty (Null) PoolID records; open the qryCalcMLC_PC_OMOrder_PNC query in design view and add Is Not Null in the criteria row for the PoolID (you only get 72 records not null in the sample).

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  12. #12
    mlrucci is offline Competent Performer
    Windows 7 64bit Office 365
    Join Date
    Apr 2018
    Posts
    202
    Whoop Whoop, That was it!! Thank you very much for your help!! Made my day. Have been trying for hours and was really stuck. Have a great New Years!


  13. #13
    mlrucci is offline Competent Performer
    Windows 7 64bit Office 365
    Join Date
    Apr 2018
    Posts
    202
    Here is one for you, as the code reads in the module, it extracted the number in the string, but also causes a problem with the section I want to keep

    Original:
    UR2MPSRR_10292021

    Result: It has a number in the string causing
    #Func!

    Need:
    UR2MPSRR

    Is there a way make this work.. I have 31,000 entries and 3,000 have this issue and do not want to do it manually. Ideas?

  14. #14
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    try this function instead
    Code:
    Function loseDate(txt)
    Dim i As Integer
    
    
        txt = Nz(txt, "")
    
    
        For i = 1 To Len(txt) - 8
    
    
            If IsNumeric(Mid(txt, i, 8)) Then Exit For
    
    
        Next i
    
    
        If txt <> "" Then loseDate = Left(txt, i - 2)
    
    
    End Function

  15. #15
    mlrucci is offline Competent Performer
    Windows 7 64bit Office 365
    Join Date
    Apr 2018
    Posts
    202
    That did it. Thank you!!!!!! What a long day. You are the best.

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

Similar Threads

  1. DMax +1 a field with alpha and numeric characters
    By beewerks in forum Programming
    Replies: 6
    Last Post: 02-12-2018, 05:06 PM
  2. creation alpha numeric code
    By Jen0dorf in forum Access
    Replies: 1
    Last Post: 05-09-2016, 11:52 AM
  3. Replies: 1
    Last Post: 03-09-2014, 06:30 PM
  4. Alpha Numeric auto id?
    By arshadmgic in forum Forms
    Replies: 7
    Last Post: 09-02-2012, 03:00 AM
  5. Recordset not showing alpha-numeric entries
    By rayhawk in forum Access
    Replies: 9
    Last Post: 10-29-2010, 08:15 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