Link to home
Start Free TrialLog in
Avatar of sdesar
sdesar

asked on

how to strip characters ?

How do i fix the function below so it gets called only if there are vbCr or vbCrLf ?

Currently it gets called all the time...

Any suggestions...

Public Function removeChars(s As String) As String
  Dim str   As String
  Dim i     As Integer
 
  For i = 1 To Len(s)
    Select Case Mid(s, i, 1)
      Case vbCr, vbLf
        str = str & vbCrLf
      Case Else
        str = str & Mid(s, i, 1)
    End Select
  Next
  removeChars = str
End Function


Private Sub STR_NOTES_BeforeUpdate(Cancel As Integer)
Me.STR_NOTES = removeChars(Me.STR_NOTES)
'cleanit (Me.STR_NOTES)
End Sub
Avatar of richardlee
richardlee

Hi

You might want to try to search for this character first vbCR or vbCRLF.  Try using InStr function.  It will return the position of the string found.  If 0, then not found, else you've got it.  When you've found the vbCR or vbCRLF character, then call the RemoveChars function.

Have a go at it.

-richard

ASKER CERTIFIED SOLUTION
Avatar of gregdaly
gregdaly

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial