In Access, the Replace function returns a string in which a sequence of characters has been replaced with another set of characters a specified number of times.
The syntax for the Replace function is:
Replace ( expression, find, replacement, [start, [count, [compare]]] )
The return value of the Replace function is a string, that begins at the position specified by start and concludes at the end of the expression string. It is not a copy of the original string from start to finish.
expression is the string expression containing substring to replace.
find is the substring being searched for in expression.
replacement will replace find in expression.
start is optional. This is the position in expression to begin the search. If this parameter is omitted, 1 is assumed.
count is optional. This is the number of substitutions to perform. If omitted, the default value is 1, which means make all possible substitutions.
compare is optional. The following is a list of valid parameters:
|vbUseCompareOption||1||Performs a comparison using the setting of the Option Compare statement.|
|vbBinaryCompare||0||Performs a binary comparison.|
|vbTextCompare||1||Performs a textual comparison.|
|vbDatabaseCompare||2||Performs a comparison based on information in your database|
This example uses the replace function to change the apples color. Now the MyResult variable would contain the value “Red Apple”.
You can also use the Replace function in a query.
You cannot test this function online. It works in Access only.