Results 1 to 11 of 11
  1. #1
    MichaelA is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2019
    Location
    Wisconsin
    Posts
    139

    Help with Code from a Blog Site

    I found a blog that describes something I want to do but there seems to be a problem with a couple lines in the code provided. The blog is here:



    https://www.microsoft.com/en-us/micr...h-as-you-type/

    I changed text color of the offending lines of code to red.

    Code:
    Private Sub cboFilter_Change()
    
    
      ' If the combo box is cleared, clear the form filter.
      If Nz(Me.cboFilter.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.cboFilter.ListIndex <> -1 Then
        Me.Form.Filter = “[Company] = ‘” & _
                         Replace(Me.cboFilter.Text, “‘”, “””) & “‘”
        Me.FilterOn = True
       
      ' If a partial value is typed, filter for a partial company name match.
      Else
        Me.Form.Filter = “[Company] Like ‘*” & _
                         Replace(Me.cboFilter.Text, “‘”, “””) & “*'”
        Me.FilterOn = True
    
    
      End If
     
      ' Move the cursor to the end of the combo box.
      Me.cboFilter.SetFocus
      Me.cboFilter.SelStart = Len(Me.cboFilter.Text)
    
    
    End Sub
    Thank you very much!

  2. #2
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Hi

    Have you created the Form as a Split Form

    Do you have a Control on the Form named "Company"?

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    The problem, I'm pretty sure, is that that blog gave the code as

    Me.Form.Filter = [Company] = ‘” & _
    Replace(Me.cboFilter.Text, “‘”, “””) & “‘”

    and the VBA code window doesn't accept these types of symbols...they have a specific name but I can't remember it.

    But go into the code window and replace the slanted Single and Double Quotes with " and ' Quotes, which are the ones the code editor uses and recognizes.

    Do the same for the code in the Else clause.

    Linq ;0)>

  4. #4
    MichaelA is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2019
    Location
    Wisconsin
    Posts
    139
    Quote Originally Posted by mike60smart View Post
    Hi

    Have you created the Form as a Split Form

    Do you have a Control on the Form named "Company"?
    Yes, I created a split form. I don't have a control called "Company." Mine is named "Title" but I changed the appropriate parts of the code.

    Thank you!

  5. #5
    MichaelA is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2019
    Location
    Wisconsin
    Posts
    139
    Quote Originally Posted by Missinglinq View Post
    The problem, I'm pretty sure, is that that blog gave the code as

    Me.Form.Filter = [Company] = ‘” & _
    Replace(Me.cboFilter.Text, “‘”, “””) & “‘”

    and the VBA code window doesn't accept these types of symbols...they have a specific name but I can't remember it.

    But go into the code window and replace the slanted Single and Double Quotes with " and ' Quotes, which are the ones the code editor uses and recognizes.

    Do the same for the code in the Else clause.

    Linq ;0)>
    I did what you suggested. Now, I'm getting an "Expected: list separator or )" message from the ElseIf statement. The last single quote in the ElseIf statement is highlighted and I get an "Expected: end of statement" error in the Else statement and [Title] is highlighted.

    NOTE: I changed [Company] to [Title] to match my form.

    Thank you, in advance!

  6. #6
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Hi

    Can you post the SQL that you have used?

  7. #7
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Hi


    Try this:-

    Code:
    Me.Form.Filter = "[Company] = '" & _
    Replace(Me.cboFilter.Text, "'", """) & "'"

  8. #8
    MichaelA is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2019
    Location
    Wisconsin
    Posts
    139
    Mike,

    Thank you for your time and help. I found another code that accomplished the same thing. I went with this...

    Code:
    Private blnSpace As Boolean
    
    
    
    
    Private Sub cboFilter_Change()
        If blnSpace = False Then
            Me.Requery
            Refresh
            cboFilter.SetFocus
            cboFilter.SelStart = Len(Me.cboFilter.Text)
        End If
    End Sub
    
    
    Private Sub cboFilter_KeyPress(KeyAscii As Integer)
        If KeyAscii = 32 Then
            blnSpace = True
        Else
            blnSpace = False
        End If
    End Sub

  9. #9
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Just so you know...

    Me.Form.Filter = "[Company] = '" & _
    Replace(Me.cboFilter.Text, "'", """)

    should have been

    Me.Form.Filter = "[Company] = '" & _
    Replace(Me.cboFilter.Text, "'", """")

    replacing an apostrophe with ""...a Zero-Length String.

    When doing this sort of thing...your Quote marks (the Doubles, in this case) have to be in pairs. In the first example there are 7 Double Quotes, not 8.

    Glad you got it working!

    Linq ;0)>

  10. #10
    MichaelA is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2019
    Location
    Wisconsin
    Posts
    139
    Quote Originally Posted by Missinglinq View Post
    Just so you know...

    Me.Form.Filter = "[Company] = '" & _
    Replace(Me.cboFilter.Text, "'", """)

    should have been

    Me.Form.Filter = "[Company] = '" & _
    Replace(Me.cboFilter.Text, "'", """")

    replacing an apostrophe with ""...a Zero-Length String.

    When doing this sort of thing...your Quote marks (the Doubles, in this case) have to be in pairs. In the first example there are 7 Double Quotes, not 8.

    Glad you got it working!

    Linq ;0)>
    OK, that's why I was getting the "Expected: End of Statement" error.

    Thank you! I appreciate your time and help.

  11. #11
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    Good luck with your project!

    Linq ;0)>

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

Similar Threads

  1. Replies: 1
    Last Post: 03-17-2017, 11:52 AM
  2. My Blog - Obscure Topics
    By AccessPower in forum Tutorials
    Replies: 0
    Last Post: 02-06-2017, 10:15 AM
  3. Replies: 1
    Last Post: 10-28-2016, 03:00 PM
  4. Replies: 1
    Last Post: 07-08-2013, 01:09 PM
  5. Embedding Dynamic Reports in Wordpress Blog
    By iansan5653 in forum Reports
    Replies: 12
    Last Post: 02-01-2012, 04:47 PM

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