I am using this code to find line breaks in a string of text retrieved from our ERP system and replacing it with a carriage return on my report.
Dim strNotes As String
Dim strFormatNotes As String
Dim intEnterPos As Integer
Dim i As Integer
strNotes = Me.COLIN_XTXT
ReDim strTemp(0) As String
intEnterPos = InStr(strNotes, Chr(13))
Do Until intEnterPos = 0
ReDim Preserve strTemp(UBound(strTemp) + 1) strTemp(UBound(strTemp)) = Trim$(Left$(strNotes, intEnterPos - 1))
strNotes = LTrim$(Right$(strNotes, Len(strNotes) - intEnterPos))
intEnterPos = InStr(strNotes, Chr(13))
Loop
For i = 1 To (UBound(strTemp))
If strTemp(i) = Chr(13) Then
Exit For
End If
strFormatNotes = strFormatNotes & " " & strTemp(i)& vbCrLf
Next i
Me.FormatedNotes = strFormatNotes
I am getting a subscript out of range error and I lose text after my last line break. Will someone please tell me what I am doing wrong!
Dim strNotes As String
Dim strFormatNotes As String
Dim intEnterPos As Integer
Dim i As Integer
strNotes = Me.COLIN_XTXT
ReDim strTemp(0) As String
intEnterPos = InStr(strNotes, Chr(13))
Do Until intEnterPos = 0
ReDim Preserve strTemp(UBound(strTemp) + 1) strTemp(UBound(strTemp)) = Trim$(Left$(strNotes, intEnterPos - 1))
strNotes = LTrim$(Right$(strNotes, Len(strNotes) - intEnterPos))
intEnterPos = InStr(strNotes, Chr(13))
Loop
For i = 1 To (UBound(strTemp))
If strTemp(i) = Chr(13) Then
Exit For
End If
strFormatNotes = strFormatNotes & " " & strTemp(i)& vbCrLf
Next i
Me.FormatedNotes = strFormatNotes
I am getting a subscript out of range error and I lose text after my last line break. Will someone please tell me what I am doing wrong!