Counting number of line in a memo field

  • Thread starter Thread starter J9
  • Start date Start date
How would it know what a line is? If your field is an inch wide, a few
words might take several lines. If it is 6 inches wide, then you can fit a
sentence or two on one line. In the table, there are no 'lines' to count.

Rick B


Is there a function that will return an integer number of
lines in a memo field?

Thanks
 
I'm going to go with everytime there is a carriage
return, it counts as a new line.

What you need to do is create a User Defined function to count the
number of occurrences of chr(13) there are in the field.
Copy this function to a Module.

Public Function CountLines(FieldIn As String) As Integer
Dim intX As Integer
Dim intY As Integer
intX = InStr(FieldIn, Chr(13))
intY = 1
Do While intX <> 0
intX = InStr(intX + 1, FieldIn, Chr(13))
intY = intY + 1
Loop
CountLines = intY
End Function

Then call it from a query:
Lines:CountLines([FieldName])
Add criteria to the query:
Where [FieldName] Is Not Null

Or .....
From a Report (or Form) you would use an unbound control.
Set it's Control Source to:

=IIf(IsNull([FieldName]),"0",CountLines([FieldName]))
 
Back
Top