Results 1 to 3 of 3

Thread: filter problem

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    35
    I am trying to filter a recordset.
    ie rstSetName.Filter = "KEYFIELD = '" & varName & "'"

    My problem: if there is a ' or a " in varName it ends the string for my filter and messes it up. I have been told to do something like this.

    rstSetName.Filter = "KEYFIELD = '" & replace(varName, "'", "''" & "'")

    This does stop the filter from crashing, however it doesn't really solve my problem because the filter is incorrect, and doesn't find the data I want it to. I have been scratching my head over this one for a while, so any help would be super cool!

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    The solution you had is almost correct:
    Code:
    rstSetName.Filter = "KEYFIELD = '" & Replace(varName, "'", "''") & "'"


  3. #3
    Addicted Member
    Join Date
    Sep 2000
    Posts
    219
    Try this.

    rstSetName.Filter = "KEYFIELD = '" & Replace(Replace(varName, "'", ""), chr(34), "") & "'"


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