Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2013
    Posts
    87

    Unanswered: Code help for text string delimiters

    Good morning,

    I found the following code on an Access site that appears to do exactly what I am looking for. In a Combo box - type in a string and have combo box bring up matches anywhere in string.

    I have looked at the code for quite a while now and I cannot find the problem. I think it must be in the single and double quotes. I have always had a lot of trouble wt how to delimit different strings. I have never found a tutorial that helped me. I would love any direction as to where to look so I can learn this once and for all. Meanwhile . . .

    Here is the code. The two underline lines are tone that are giving me a problem:

    Code:
    Private Sub cboLocation_Change()
    
     If the combo box is cleared, clear the form filter.
    	If Nz(Me.cboLocation.Text) =  Then
    		Me.Form.Filter = 
        		Me.FilterOn = False
    
     If a combo box item is selected, filter for an exact match.
     Use the ListIndex property to check if the value is an item in the list.
      	ElseIf Me.cboLocation.ListIndex <> -1 Then
        		Me.Form.Filter = [Location] =  & Replace(Me.cboLocation.Text, , ) & 
        		Me.FilterOn = True
    
     If a partial value is typed, filter for a partial location match.
      	Else
        		Me.Form.Filter = [Location] Like * & Replace(Me.cboLocation.Text, , ) & *'
        		Me.FilterOn = True
    
      	End If
    
     Move the cursor to the end of the combo box.
      	Me.cboLocation.SetFocus
      	Me.cboLocation.SelStart = Len(Me.cboLocation.Text)
    
    End Sub
    Many thanks,
    Scott

  2. #2
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    630
    Provided Answers: 35
    I think youre using too many different quotes.
    single quote, ' , (next to the enter key), works fine for almost all, EXCEPT if the single quote is in a name like O'malley. Then single quote will fail. But if you never have this ,stick with single quotes.

    Me.Form.Filter = [Location] = ' & cboLocation & "'"

    If you want to use double quotes, ", i set a constant Q to the dbl quote ,then surround text with that:
    Code:
    const Q = """"
    Me.Form.Filter = [Location] like  & Q & "*" & cboLocation & "*" &  Q

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •