Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem Filtering ADO Recordset

Status
Not open for further replies.

jhein

Programmer
Feb 17, 2003
46
0
0
CA
I have a function that is trying to filter an ADO recordset. It works just fine until I try to filter the recordset on a value that contains an apostrophe. Is there anyway of getting around this? The code I am using looks like the following:

adoCloneRS.Filter = "descr = '" & Trim(Me.txtCls.Text) & "'"

This works great until the value I am trying to filter on contains an apostrophe. Any suggestions? Thanks in advance.
 
remove the single quotes and replace them with chr(34) on each end of your string.

chr(34) = "

try this:

adoCloneRS.Filter = "descr = " & chr(34) & Trim(Me.txtCls.Text) & chr(34)

hope this helps!
 
Thanks for the tip. I did manage to do something that seems to be working. Instead of just using the following code:

adoCloneRS.Filter = "descr = '" & Trim(Me.txtCls.Text) & "'"

I have done the following, which is working now:

Dim strClsDescr as String

strClsDescr = Replace(Trim(Me.txtCls.Text), "'", "''")

adoCloneRS.Filter = "descr = '" & strClsDescr & "'"

Basically if the replace function doesn't see any apostrophies then it does nothing...if it does see one then it replaces it with ''
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top