Results 1 to 3 of 3
  1. #1
    joshynaresh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    131

    Getting Result excluding number Character where number and Alphabets character mixed in same field

    Dear Sir,



    I want to get result only alphabets character if there are alphabet and number characters in same field. Can it is possibe to extract only Alphabet character from mixed character in same field. for example I hvae uploaded JPG. There is two types of Required Result. 1 is excluding number only and another reuiered result is excluding number and other special charecter (Alphabets only

    Click image for larger version. 

Name:	sample.jpg 
Views:	22 
Size:	54.2 KB 
ID:	35344

    Thanks in advance.
    Attached Thumbnails Attached Thumbnails sample.jpg   sample.jpg  

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    This needs a VBA custom function. I am sure question has been asked many times. Here is one http://www.utteraccess.com/forum/lof.../t1124576.html
    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
    JSR is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2018
    Location
    Reno, NV
    Posts
    41
    It's not going to be exactly what you want, because for #3, you want to replace (space)977(space) with (space), whereas with #6, you want to replace 34 with (space). That kind of logic would be more difficult to program than what I just wrote:

    Code:
    Public Function RemoveNums(InputStr As String) As String
    'remove numbers and duplicate spaces that result from numbers surrounded by spaces
    
    Dim ResultStr As String
    Dim L As Integer
    Dim m As String
    Dim i As Integer
    
    ResultStr = ""      'initialize
    
    For i = 1 To Len(InputStr)
      m = Mid(InputStr, i, 1)
      
      If Asc(m) >= 48 And Asc(m) <= 57 Then      'digits 0-9
        'skip it
      Else
        ResultStr = ResultStr & m
      End If
    Next i
    
    'replace duplicate spaces with one space
    L = Len(ResultStr)
    i = 1
    
    Do While i < L
      If Mid(ResultStr, i, 2) = "  " Then
        ResultStr = Left(ResultStr, i) & Right(ResultStr, Len(ResultStr) - i - 1)
        L = L - 1       'length is one less due to removal of duplicate space
      Else
        i = i + 1       'move to the next character (leave i alone in case of 3 or more duplicate spaces in a row)
      End If
    Loop
    
    'delete trailing space
    If Right(ResultStr, 1) = " " Then
      ResultStr = Left(ResultStr, Len(ResultStr) - 1)
    End If
    
    RemoveNums = ResultStr
    
    End Function
    
    Public Function RemoveAllButLetters(InputStr As String) As String
    
    Dim ResultStr As String
    Dim L As Integer
    Dim m As String
    Dim i As Integer
    
    ResultStr = ""      'initialize
    
    For i = 1 To Len(InputStr)
      m = Mid(InputStr, i, 1)
      
      If (Asc(m) >= 97 And Asc(m) <= 122) Or (Asc(m) >= 65 And Asc(m) <= 90) Or Asc(m) = 32 Then    'a-z or A-Z or space
        ResultStr = ResultStr & m
      End If        'else skip it
    Next i
    
    'replace duplicate spaces with one space
    L = Len(ResultStr)
    i = 1
    
    Do While i < L
      If Mid(ResultStr, i, 2) = "  " Then
        ResultStr = Left(ResultStr, i) & Right(ResultStr, Len(ResultStr) - i - 1)
        L = L - 1       'length is one less due to removal of duplicate space
      Else
        i = i + 1       'move to the next character (leave i alone in case of 3 or more duplicate spaces in a row)
      End If
    Loop
    
    'delete trailing space
    If Right(ResultStr, 1) = " " Then
      ResultStr = Left(ResultStr, Len(ResultStr) - 1)
    End If
    
    RemoveAllButLetters = ResultStr
    
    End Function
    Then, you simply run a query:
    select SN, RemoveNums([NameField]) from [table name]

    and:
    select SN, RemoveAllButLetters(RemoveNums([NameField])) from [table name]

    which will produce:
    Code:
    3   Mr. Shyam 977 Nepal    Mr. Shyam Nepal    Mr Shyam Nepal
    6   Sohan 34-23-56         Sohan --           Sohan

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

Similar Threads

  1. Replies: 2
    Last Post: 01-05-2018, 04:35 PM
  2. Replies: 18
    Last Post: 10-11-2017, 03:07 PM
  3. Replies: 9
    Last Post: 01-10-2014, 02:50 PM
  4. SQL wildcard character excluding
    By sandlucky in forum Access
    Replies: 2
    Last Post: 03-28-2011, 03:33 AM
  5. filter by the number of character
    By bangemd in forum Access
    Replies: 1
    Last Post: 06-30-2009, 10:33 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