Solved Replace multiple spaces

jack555

Member
Local time
Today, 16:57
Joined
Apr 20, 2020
Messages
93
Code:
Replace(me.txtName,"  "," ")
above code can be used to remove double spaces between two words in a string. However, if there are three or four spaces that randomly occurs, how can we strip all these extra spaces and keep only one space? Tried adding nested "replace" without success.

Any suggestions are welcome.
 
Code:
me.txtName = Replace(me.txtName,"  "," ")
Do While Instr(1, Me.txtName, "  ") <> 0
    me.txtName = Replace(me.txtName,"  "," ")
Loop
 
Depending on how many occurrences you anticipate, you could try

Replace(me.txtName," "," ",,9)

where 9 is >= the number of occurrences
 

Users who are viewing this thread

Back
Top Bottom