Results 1 to 5 of 5
  1. #1
    auerdl is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    6

    strip space if after a comma

    Sorry I entered this post in the wrong area. Please ignore, I will re post in right place



    The below code was posted by spideynok. my greatest thanks!!

    One question...
    The below takes the search word(s) delimited my a comma and searches a field.

    On the below code, if the user enters a comma and space between search words, how can I strip the space, but strip the space only if it is after the comma?


    Private Sub Command25_Click()
    Dim strFilter As String, strFilters() As String
    Dim intX As Integer

    With Me
    strFilters = Split(Nz(.Text23, ""), ",")
    For intX = 0 To UBound(strFilters)
    strFilter = strFilter & _
    Replace(" OR ([EmployeeName] Like '*%F*')", _
    "%F", strFilters(intX))
    Next intX
    .Filter = Replace(Mid(strFilter, 5), "'", Chr(34))
    .FilterOn = (.Filter > "")
    End With
    End Sub

  2. #2
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,840
    Trim function will remove trailing spaces. You could put it within the string building part, like Trim(strfilter). I presume you mean the very last space is to be removed and not somewhere in between.
    Last edited by Micron; 07-16-2016 at 05:48 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    auerdl is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    6
    How o I make sure it is only after the comma.

    example
    blue bug, red
    remove the space after the comma and not blue

    I am not so good at code, can you give me the example

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,840
    Try changing your line to this
    Code:
    Replace(" OR ([EmployeeName] Like '*%F*')", _
    "%F", Trim(strFilters(intX)))
    I forgot that Trim will remove leading AND trailing spaces.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by auerdl View Post
    Sorry I entered this post in the wrong area. Please ignore, I will re post in right place

    The below code was posted by spideynok. my greatest thanks!!

    One question...
    The below takes the search word(s) delimited my a comma and searches a field.

    On the below code, if the user enters a comma and space between search words, how can I strip the space, but strip the space only if it is after the comma?


    Private Sub Command25_Click()
    Dim strFilter As String, strFilters() As String
    Dim intX As Integer

    With Me
    strFilters = Split(Nz(.Text23, ""), ",")
    For intX = 0 To UBound(strFilters)
    strFilter = strFilter & _
    Replace(" OR ([EmployeeName] Like '*%F*')", _
    "%F", strFilters(intX))
    Next intX
    .Filter = Replace(Mid(strFilter, 5), "'", Chr(34))
    .FilterOn = (.Filter > "")
    End With
    End Sub
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
    Evidently this is crossposted: http://www.mrexcel.com/forum/microso...ml#post4579481


Please reply to this thread with any new information or opinions.

Similar Threads

  1. Strip Security from Access 2003
    By agarvan in forum Access
    Replies: 4
    Last Post: 08-13-2013, 11:05 AM
  2. Replies: 1
    Last Post: 05-02-2013, 10:57 AM
  3. function to strip characters
    By Kirsti in forum Queries
    Replies: 2
    Last Post: 11-01-2012, 07:53 PM
  4. Strip input mask in query results?
    By Stan Denman in forum Queries
    Replies: 1
    Last Post: 06-05-2012, 02:16 PM
  5. Replies: 4
    Last Post: 10-15-2010, 07:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums