Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of returns in memo field 1

Status
Not open for further replies.

Netherby

Programmer
Nov 9, 2001
32
GB
How can I examine the contents of a memo field and count the number of vbCrLf characters? Thanks.
 
This is this works. I did not check it in detail
Code:
Public Function getCrLF(memFld) As Integer
  Dim pos As Integer
  pos = 1
  Do
    If Nz(InStr(pos, memFld, vbCrLf)) = 0 Then
      Exit Function
    End If
  pos = InStr(pos, memFld, vbCrLf) + 1
  getCrLF = getCrLF + 1
  Loop
End Function
SELECT getCrLF([memoFld]) AS CountReturnt
FROM tblmemo;
 
Actually this may be better:

Public Function CountCRLF(mem As Variant) As Integer
CountCRLF = (Len(mem) - Len(Replace(mem, vbCrLf, ""))) / 2
CountCRLF = (Len(mem) - Len(Replace(mem, Chr(13) & Chr(10), ""))) / 2
End Function

I added the check for chr(13) & chr(10)
 
Thanks MajP. I prefer your second post as it cuts out the do loop.
 
I did not verify against real data. Does it work?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top