Count how many lines stored in a field.

mafhobb

Registered User.
Local time
Today, 07:41
Joined
Feb 28, 2006
Messages
1,249
Is there any way to count how many lines of text are stored in a particular table field? How about counting how many times was the "enter" key pressed?

Thanks

Mafhobb
 
"lines" are usually terminated with vbCrLf. You could try counting those characters or maybe just the LF or CR by itself would work. Post back if you need help with the function.
 
Here's a function to get you started:
Code:
Public Function CountLines(InString As String) As Integer
Dim Counter As Integer
CountLines = 1
For Counter = 1 To Len(InString)
   If Mid(InString, Counter, 1) = Chr(13) Then
      CountLines = CountLines + 1
   End If
Next
End Function
Called by: YourInteger = CountLines(Me.YourTextBox)
...using your control names of course.
 
Thank you Ruralguy. Sorry I did not respond earlier, but I went on vacation and just did not think of access at all...

Anyway, Let's say that I have a field in a form (Projects) that is called (pminput). How do I count the characters on that specific field using your example. Also, do I add the code on formload or odirty or afteredit?

Thanks


Mafhobb
 
Assuming you have put the code I supplied in yout form's class module then
I'll get you started with code for the Current event of the form:
Code:
Private Sub Form_Current()
   MsgBox "The number of lines in the pminput control is [" & CountLines(Me.pminput) & "]"
End Sub
 

Users who are viewing this thread

Back
Top Bottom