I am trying to make a reporting tool where the users can easily replace with a field value by putting square brackets around a field name to be replaced.
So say I had a table, x
Field name: Salutation
Datum: Hello World
Now lets say my Record source included x.Salutation.
Lets say another Field, y had the rich text value "<div>Sincerely, </div><div>[Salutation]</div>"
I would like to make my control source...
=fnReplace
And end up with the returned value
"<div>Sincerely, </div><div>Hello World</div>"
I had reservations about finding the value but decided to give it a go with a function in the report but I did not see a clever solution...
Is there anything that will work without tanking the performance? Or do I just need to embed all the replaces in the control source (an interesting alternative coding task)?
So say I had a table, x
Field name: Salutation
Datum: Hello World
Now lets say my Record source included x.Salutation.
Lets say another Field, y had the rich text value "<div>Sincerely, </div><div>[Salutation]</div>"
I would like to make my control source...
=fnReplace
And end up with the returned value
"<div>Sincerely, </div><div>Hello World</div>"
I had reservations about finding the value but decided to give it a go with a function in the report but I did not see a clever solution...
Is there anything that will work without tanking the performance? Or do I just need to embed all the replaces in the control source (an interesting alternative coding task)?
Code:
Public Function fnReplace(FixIt As String) As String
Dim strField As String
Dim lngStartPos As Long
While InStr(1, FixIt, "[")
lngStartPos = InStr(1, FixIt, "[")
strField = Mid(FixIt, lngStartPos)
strField = Left(strField, InStr(1, strField, "]"))
FixIt = Replace(FixIt, strField, Me.Controls(strField).Value) 'This doesn't work as there is no control but what is the right collection or method...
Wend
fnReplace = FixIt
End Function