I'm trying to searh a memo field for carriage return, line feed. When found,
I'd like to insert the number 1 on the first occurance, 2 on the second
occurance, 3 on the the next and so on... Is there a way I can do this?
Thanks in advance.
It's not at all clear what you expect to get from this.
An example would have been helpful, as would your Access version
number.
If your data in the memo field looked like this.
Line A.
Line B.
Line C.
Line D.
Code a command button click event on your form:
Me![MemoField] = AddNumbers([MemoField])
Copy and paste the code below into the form module.
Public Function AddNumbers(strIn As String) As String
Dim intX As Integer
Dim intY As Integer
Dim intZ As Integer
intZ = 1
intX = InStr(strIn, Chr(10))
Do While intX <> 0
strIn = Left(strIn, intX) & intZ & Mid(strIn, intX + 1)
intZ = intZ + 1
intY = intX + 1
intX = InStr(intY, strIn, Chr(10))
Loop
AddNumbers = strIn
End Function
Your data will then look like this:
Line A.
1Line B.
2Line C.
3Line B.
However.....
To display the above datas as:
Line A.1
Line B.2
Line C.3
Line D.4
change the function to:
Public Function AddNumbers(strIn As String) As String
Dim intX As Integer
Dim intY As Integer
Dim intZ As Integer
intZ = 1
intX = InStr(strIn, Chr(10))
Do While intX <> 0
strIn = Left(strIn, intX - 2) & intZ & Mid(strIn, intX - 1)
intZ = intZ + 1
intY = intX + 2
intX = InStr(intY, strIn, Chr(10))
Loop
strIn = strIn & intZ
AddNumbers = strIn
End Function