?
Solved

how to strip characters ?

Posted on 2003-02-25
2
Medium Priority
?
265 Views
Last Modified: 2012-06-22
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
0
Comment
Question by:sdesar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Expert Comment

by:richardlee
ID: 8022027
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

0
 
LVL 3

Accepted Solution

by:
gregdaly earned 80 total points
ID: 8022044
If I read your note correctly you want to modify Private Sub STR_NOTES_BeforeUpdate so that it calls removeChars only if STR_NOTES contains either vbCr or vbCrLf or both.

The specific ANSI character code for Cr is Chr(13) and Lf is Chr(10).  You want to test the STR_NOTES for the presence of these characters using the INSTR function.  INSTR returns 0 if the search string is not found.

Here's how I would write it:

Private Sub STR_NOTES_BeforeUpdate(Cancel As Integer)
Dim vstr As String
vstr = me.STR_NOTES
If InStr(1, vstr, Chr(13)) > 0 Or InStr(1, vstr, Chr(10)) > 0 Then
    vstr = removeChars(vstr)
    me.STR_NOTES = vstr
End If
End Sub
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question