Breaking text into two parts in a report after 13 lines.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to break the text in my details field into two parts at the end of the
13th line between two words, and place the 2nd part on a differt field on the
2nd page.
 
I'm not sure we know anything about your "details field" since "detail" is a
section in a report and has other meanings. We also have no way of
understanding what/where/how the "lines" are generated.
 
Sorry, The details field we'll call narrative which is stored in a access xp
memo field and input from a form with enter behavior set to new line. So,
the narrative needs to be broken down into lines (using courrier new font) of
80 characters in leanth or a vbLF. the lines need to be counted and any
lines after 13 need to be reconstruted into orriginal format minus the 13
lines and paced into a text box on the 2nd page of the report.
 
Do you need to break at exactly 80 or do you need to find a space at or
before 80? Do you have code to do this? Or, do you want a code that accepts
the memo field text and returns either the first or second section divided
into lines with embedded vbCrLf between words so that no line exceeds 80
characters? The first and second sections would be divided based on the
first 13 lines and the remaining lines?
 
sorry for the poor communication.
1. I need to find the space at or before 80
2. I'm trying to make the code to accept the memo field text and return the
second section as a string or query field. i.e. query
field=funSplitText([memo field], lines to break at)
3. returned string would be the beginning of the 14th line to the end of the
input string.

the code i have so far, which has problems:

Public Function funSplitTxt2(strTxt As String, intBreakLine As Integer) As
String
Dim astrLF() As String
Dim astrWords() As String
Dim strTmp, strText As String
Dim intUbLf, i, intLines As Integer
Dim aLines() As Variant

astrLF() = Split(strTxt, vbLf)
intUbLf = UBound(astrLF())
MsgBox LBound(astrLF()) & vbLf & intUbLf
ReDim aLines(intUbLf + 1)
intLines = 0

For i = 0 To intUbLf
Dim astrLines() As String

If Len(astrLF(i)) > 80 Then
Dim intUbW, intI, intL, intLen As Integer

astrWords() = Split(astrLF(i))
intUbW = UBound(astrWords())
intI = 0
intL = 0
strTmp = ""
Do Until intI = intUbW + 1
intLen = Len(strTmp) + Len(astrWords(intI)) + 1
Select Case intLen
Case Is < 80
strTmp = strTmp & " " & astrWords(intI)
intI = intI + 1
Case 80
strTmp = strTmp & " " & astrWords(intI)
ReDim Preserve astrLines(intL + 1)
astrLines(intL) = Trim(strTmp)
MsgBox "@" & Trim(strTmp) & "@"
strTmp = ""
intL = intL + 1
intI = intI + 1
intLines = intLines + 1
Case Is > 80
ReDim Preserve astrLines(intL + 1)
astrLines(intL) = Trim(strTmp)
MsgBox "@" & Trim(strTmp) & "@"
strTmp = ""
intL = intL + 1
intLines = intLines + 1
End Select
Loop
If Len(strTmp) > 0 Then
ReDim Preserve astrLines(intL + 1)
astrLines(intL) = Trim(strTmp)
intLines = intLines + 1
MsgBox "@" & Trim(strTmp) & "@"
End If
Else
MsgBox CStr(Asc(Right$(astrLF(i), 1)))
astrLines(0) = Replace(astrLF(i), vbCr, "")
intLines = intLines + 1
MsgBox "@" & Trim(astrLF(i)) & "@"
End If
aLines(i) = astrLines()
Next i

strTmp = ""
Dim astrLF2() As String
ReDim astrLF2(intUbLf + 1)
For i = 0 To intUbLf
Dim astrLines2() As String
astrLines2() = aLines(i)
strTmp = Join(astrLines2())
astrLF2(i) = strTmp
strTmp = ""
Next i
strText = Join(astrLF2(), vbNewLine)
'strText = Join(astrLF(), vbLf)
MsgBox "Lines: " & intLines
funSplitTxt2 = strText
End Function

I am not the best programer. I'm an entirly self taught amatur.
 
Back
Top