Query Version of Find and Replace (1 Viewer)

tension22

New member
Local time
Yesterday, 18:04
Joined
May 22, 2010
Messages
3
Hi,

I need a query that works exactly like find and replace function. I have tried many ways, but the result is always the same - the whole string gets changed, not just the character/s in need.

So if I need all "!" exclamation remarks changing to a "?" question mark it will do it.

So would change this:

Help!
Oi!
Hi!
Hello!

to

Help?
Oi?
Hi?
Hello?


Also note that I can't just do an update query to find

Help!
Oi!
Hi!
Hello!

and replace with:

Help?
Oi?
Hi?
Hello?

Its must only work on finding the ! and replacing with ?, just like find and replace.

Thanks
 

Brianwarnock

Retired
Local time
Today, 02:04
Joined
Jun 2, 2003
Messages
12,701
Use of the search facility will show that this has been asked before.

Brian
 

FoFa

Registered User.
Local time
Yesterday, 20:04
Joined
Jan 29, 2003
Messages
3,672
Query using like to find it, and replace function
 

darwin25

New member
Local time
Today, 09:04
Joined
May 26, 2010
Messages
8
create a function in Module


Function FindReplace(FindString As String, Substitute As String, StringExpr As String) As String

Dim n_Pos As Integer

While InStr(StringExpr, FindString)

n_Pos = InStr(StringExpr, FindString)
StringExpr = Mid(StringExpr, 1, n_Pos - Len(FindString) + 3) & Substitute & Mid(StringExpr, n_Pos + Len(FindString), Len(StringExpr) - n_Pos)
Wend


FindReplace = StringExpr

End Function



And use it in your query like this

FindReplace(String1,String2,Field)

where
String1 = string to Find
String2 = new value
Field = fieldname of the string expression


HTH
 

DCrake

Remembered
Local time
Today, 02:04
Joined
Jun 8, 2005
Messages
8,632
Why not use the built in Replace() function?
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 11:04
Joined
Jan 20, 2009
Messages
12,853
Why not use the built in Replace() function?

I think Darwin was just answering the question.
"I need a query that works exactly like find and replace function."

I like their subtle sense of humor.
 

lighterthief

New member
Local time
Today, 03:04
Joined
Aug 1, 2010
Messages
2
I have a similar issue.

I wish to find a particular piece of text at the end of a text field, then replace only those characters (ie only appearing at the end of the field) with "".

For example, I wish to remove " UK" from the end of a text field.

"Academy of Ukelele Players UK"

would become:

"Academy of Ukelele Players"

I have tried using the function as suggested by Darwin25 but this results in both of the previous examples returning as:

"Academy ofelele Players".

How can I specify that the text should only be replaced if it appears at the end of the field? The text fields are all of varying length, so I can't use the Replace function to replace at a fixed point, although I have tried various permutations, eg

Replace([table.name]![table.field]," UK","",len([table.name]![table.field]-3))

but with no joy. I am sure there must be an elegant solution to this problem and would be grateful for any advice.
 

Brianwarnock

Retired
Local time
Today, 02:04
Joined
Jun 2, 2003
Messages
12,701
A simple function something like

If Right(yourstring,2)="UK" then
Yourstring=Left(yourstring,len(yourstring)-2)

Brian
 

lighterthief

New member
Local time
Today, 03:04
Joined
Aug 1, 2010
Messages
2
Yup, thanks for that. Basically got myself stuck down a long and complicated route when in reality there was a much simpler solution staring at me all along. Appreciate the help :)
 

Users who are viewing this thread

Top Bottom