Results 1 to 9 of 9
  1. #1
    DaveT99 is online now Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    96

    Count Number of Characters Before the first Letter


    Can anyone help, I have spent 10mins googling this without Success
    How to count the number of characters (numbers) before the first letter, e.g. 7220BECBY the answer would be 4
    Many Thanks

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,938
    try

    len(val(myfield))

  3. #3
    DaveT99 is online now Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    96
    Many thanks, got there after a couple of tries...........and a new function learnt
    Regards
    Dave

  4. #4
    DaveT99 is online now Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    96
    Oops
    if the format is 2201E-2RS1TN9
    The above function is counting 5, ideally want it to stop when it reaches the E, i.e count of 4 numeric characters before the 1st Letter or Non Numeric Characyer
    Dave

  5. #5
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Very odd. The Val function is evaluating the string as scientific notation; 2201 to the minus 2 power which is 22.01 and has length of 5!
    Below works without the Val function.

    Code:
    Function tst(arg As String)
        Dim i As Integer
        tst=0    
        For i = 1 To Len(arg)
            If IsNumeric(Mid(arg, i, 1)) Then
                tst = tst + 1
            Else
                Exit Function
            End If
        Next i
    End Function
    Last edited by davegri; 05-03-2018 at 08:19 AM. Reason: initialized tst to zero

  6. #6
    DaveT99 is online now Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    96
    Hi Davegri
    Thanks for the FUNCTION. Do I insert in the query field build???
    Cheers
    Dave

  7. #7
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Click image for larger version. 

Name:	tst.JPG 
Views:	12 
Size:	51.5 KB 
ID:	33853

    Put the function in a module.
    Query design view shows how to use it in the query to get size of Fld1.
    You can use any string you want instead of Size.

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,938
    2201E-2 is scientific notation for 22.01 so will be interpreted as a number. Your example did not include a - so I did not think of it

    It is the E that gives it away. It may be your codes have other 'variations' so I would do a pass through your data to see if there are any other combinations that result in a misread

    removing the - won't solve it because 2201E2 is scientific notation for 220100.

    instead remove the dp

    len(replace(val(myfield),".",""))

    or change the E to another character

    len(val(replace(myfield,"E","X")))

  9. #9
    DaveT99 is online now Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    96
    Many thanks both of you..you clever and helpful people.
    The format is from a SKF bearing list
    Regards
    Dave

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

Similar Threads

  1. Replies: 4
    Last Post: 11-28-2017, 02:54 PM
  2. Limited number of characters in a table
    By thetcrew004 in forum Access
    Replies: 10
    Last Post: 07-28-2017, 06:51 AM
  3. Replies: 3
    Last Post: 02-07-2015, 10:50 AM
  4. Replies: 4
    Last Post: 09-18-2012, 05:07 AM
  5. How to count characters?
    By Jorge Junior in forum Access
    Replies: 1
    Last Post: 05-22-2011, 08:07 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