Replace a letter

  • Thread starter Thread starter florint
  • Start date Start date
F

florint

Hi,
How do i make a function that goes throug a specific field and replaces
ie. an "a" with a "b" ?
Thanks in advance.
 
florint said:
Hi,
How do i make a function that goes throug a specific field and
replaces
ie. an "a" with a "b" ?
Thanks in advance.

If you're using Access 2000 or later, you don't have to make a function;
there's one already made for you: the Replace() function. In code, to
replace values in a given string variable, you'd write something like
this:

strText = Replace(strText, "a", "b")

If you want to do this to a given field in every record of a table, you
would run an update query with SQL similar to this:

UPDATE MyTable
SET MyTextField = Replace(MyTextField, "a", "b");

*BUT* in the first release of Access 2000, you couldn't use the Replace
function directly in a query, so you had to write your own VBA "wrapper"
function that you would call from your query, and which would simply
call the Replace function with the arguments you passed it. I believe
this was corrected in one of the service packs/service releases for
Access 2000, but I'm not sure of that. It was certainly corrected by
Access 2002.
 
Back
Top