Page 3 of 3 FirstFirst 123
Results 31 to 32 of 32
  1. #31
    data808 is offline Noob
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    727
    I changed it to:
    Me.Filter = "[Genre:]='" & Me.cmbByGenre & "'"



    Then I got rid of the apostrophe in 80's and now it works.

    Crazy. I thought I could use any characters in the value list but I guess the computer gets confused. Anyway thanks for the quick response.

  2. #32
    ipisors is offline Access Developer
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    119
    Quote Originally Posted by data808 View Post
    I changed it to:
    Me.Filter = "[Genre:]='" & Me.cmbByGenre & "'"

    Then I got rid of the apostrophe in 80's and now it works.

    Crazy. I thought I could use any characters in the value list but I guess the computer gets confused. Anyway thanks for the quick response.
    The computer is doing exactly what its told .... with the apostrophe in 80's, until you escape that apostrophe, it becomes SQL syntax qualifier.

    Any time you are building up a VBA/SQL string and the text may contain single quotes, you must code to escape those punctuation marks that you don't wish to be taken as SQL syntax.

    The way to do that here will be:

    Me.Filter = "[Genre:]='" & Replace(Me.cmbByGenre,"'","''") & "'"

    After doing that, you can leave the single quote in the original text and it will work.
    In other words anytime there exists a single quote, it gets replaced in the literal text by a DOUBLE single quote. "doubling up" is the way to escape in SQL. You'll need this frequently when you begin using .Execute methods for SQL where a user may have typed O'Donnell, for example.

Page 3 of 3 FirstFirst 123
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 06-28-2013, 12:58 PM
  2. Code not working!!
    By jfn15 in forum Programming
    Replies: 6
    Last Post: 06-10-2013, 09:20 AM
  3. Code Not Working
    By Kirsti in forum Programming
    Replies: 3
    Last Post: 03-26-2012, 02:48 PM
  4. VBA Code Not working
    By jo15765 in forum Programming
    Replies: 12
    Last Post: 12-03-2010, 04:01 PM
  5. VBA Code for working with IE
    By smikkelsen in forum Programming
    Replies: 3
    Last Post: 04-15-2010, 01:05 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