Results 1 to 2 of 2

Thread: .filter statement on name with apostrophy

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    32

    .filter statement on name with apostrophy

    I have the following filter statement to narrow down to the currently logged in user.

    Code:
    Forms![Incidents List].FilterOn = False
        Forms![Incidents List].RecordSource = "Qry_Incidents"
        Forms![Incidents List].Filter = "([staff_name] like '" & username & "' or [staff_supervisor] like '" & username & "')"
        Forms![Incidents List].FilterOn = True
    The Staff_name and Staff_supervisor fields have some names with ' in the name like O'Brien.

    I get a syntax error when it encounters one.

    How can I effectively search a name like this?

    Thank you,

    Steve Hathaway
    Last edited by shathaway; Mar 7th, 2016 at 01:26 PM.

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,902

    Re: .filter statement on name with apostrophy

    You've posted I the wrong forum and we don't know what technologies you're using so the chances of you getting a useful answer are currently very low. Is this Access, SQL Server, something else. And what front end language is it? VBA, .Net?

    I can tell you that in SQLServer you escape an apostrophe by putting another apostrophe in front of it. So to query for O'Brien you can say:-
    Code:
    Where Name = 'O''Brien'
    I don't know if that's helpful to you or not though.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width