Access VBA | How to replace parts of a string with another string

Asynchronous picture Asynchronous · Dec 18, 2011 · Viewed 215k times · Source

I am trying to create a piece of code that replaces one word with another. Example: Replace Avenue with Ave and North with N. I am using MS Access, I could use SQL REPLACE Function but I want to do this in VBA using Access module so that I can attached the function to other column.

I am not sure where to start with this, so any input will be greatly appreciated.

Guy

Answer

Mitch Wheat picture Mitch Wheat · Dec 18, 2011

Use Access's VBA function Replace(text, find, replacement):

Dim result As String

result = Replace("Some sentence containing Avenue in it.", "Avenue", "Ave")