Results 1 to 5 of 5
  1. #1
    adlomb is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    3

    How do I replace characters AND THEN count the length of the output?

    So I have a field that's quite messy. The text varies, but each entry is similar to "1;2;3;;; " or ";1;2;3;4 "

    What I'm trying to do is (1) clean up the field so each entry is ONLY the numbers ("123", "12345", etc.). (2) I want to be able to count the number of numbers so that: if it's greater than or equal to 3 it returns "More Than 3", if it's less than 3 it shows "Less Than 3", or if it's blank it shows "Blank".

    I've tried everything I can think of. When I use the Replace function for either the semicolon or the extra spaces, the Len function shows the number of characters of the input, NOT the output, as I would have expected it to.



    Any help would be really appreciated!!!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    What purpose and why exactly are you using this input? Tell us what you are trying to accomplish--there may be some options.

  3. #3
    adlomb is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    3
    Quote Originally Posted by orange View Post
    What purpose and why exactly are you using this input? Tell us what you are trying to accomplish--there may be some options.

    This is ultimately for a report I'm working on, where one of the items shows the count of each of the three categories: "More Than 3", "Less Than 3", and "Blank".

  4. #4
    adlomb is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    3
    The input is just the way it is. I have no idea why there are all those semicolons and spaces!

  5. #5
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,700
    Do the replaces, then call the function to get the answer string.
    You didn't specify what you wanted if the length is exactly 3.
    Code:
    txtTarget = Replace(txtTarget,";","")
    txtTarget = Replace(txtTarget," ","")
    txtCount = fcnCount(txtTarget)
    Code:
    Function fcnCount(arg as string) as string
    Select case len(arg & vbnullstring)
        Case 0
            fcnCount = "Blank"
        Case 1,2
            fcnCount = "Less than 3"
        Case 3
            fcnCount = "Exactly 3"
        Case > 3 
            fcnCount = "More than 3"
    End Select

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

Similar Threads

  1. Removing Characters after certain length
    By MTSPEER in forum Queries
    Replies: 3
    Last Post: 09-19-2017, 07:29 AM
  2. Using Replace() for special characters
    By RayMilhon in forum Programming
    Replies: 2
    Last Post: 01-07-2017, 02:44 PM
  3. Replies: 3
    Last Post: 06-07-2012, 07:05 AM
  4. How to count characters?
    By Jorge Junior in forum Access
    Replies: 1
    Last Post: 05-22-2011, 08:07 PM
  5. replace characters in a string
    By blazixinfo@yahoo.com in forum Access
    Replies: 6
    Last Post: 08-06-2009, 03:36 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