It should happen no matter of order of fields in a
SELECT
statement. Why? Your function is written in improper way.
Have a look at example:
Option Explicit
Sub Test()
MsgBox RetNewString("AMADEUS") & vbCr & vbCr & RetNewString2("AMADEUS")
End Sub
Function RetNewString(inp As String) As String
Dim i As Integer
For i = 1 To Len(inp)
If Mid(inp, i, 1) = "A" Then
RetNewString = Replace(inp, Mid(inp, i, 1), "B")
ElseIf Mid(inp, i, 1) = "D" Then
RetNewString = Replace(inp, Mid(inp, i, 1), "E")
End if
Next
End Function
Function RetNewString2(ByVal inp As String) As String
Dim i As Integer, sRetVal As String
sRetVal = inp
For i = 1 To Len(sRetVal)
If Mid(sRetVal, i, 1) = "A" Then
sRetVal = Replace(sRetVal, Mid(sRetVal, i, 1), "B")
ElseIf Mid(sRetVal, i, 1) = "D" Then
sRetVal = Replace(sRetVal, Mid(sRetVal, i, 1), "E")
End if
Next
RetNewString2 = sRetVal
End Function
Do you see the difference?
I'd suggest you to forget about
for
loop. Why? Simple
Replace
should be enough, becasue
Replace
function changes every occurance of searched string. See the
documentation[
^].
Function ATM(ByVal inp As String) As String
inp = Replace(inp, "SearchedChar1", "ReplaceWithChar1")
inp = Replace(inp, "SearchedChar2", "ReplaceWithChar2")
ATM = inp
End Function