FredixBlog


Just my log about anything I could find enjoyable.



Replace()

author Posted by: fredometro on date Jan 1st, 2004 | filed Filed under: MS-Access

Replace a string by another string in a function. The function exists in Access 2000 and next, but not in Access 97. So here it is.
Public Function Replace(strSource As String, String1 As String, String2 As String) As String
    Dim iLoc As Integer
    Dim NewString As String
    NewString = strSource
    iLoc = InStr(NewString, String1)
    Do While iLoc > 0
        NewString = Left$(NewString, iLoc - 1) & String2 & Mid$(NewString, iLoc + 1)
        iLoc = InStr(iLoc + 2, NewString, String1)
    Loop
    Replace = NewString
   
  End Function