dbTalk Databases Forums  

Name filter problem when name has ' in it

comp.databases.ms-access comp.databases.ms-access


Discuss Name filter problem when name has ' in it in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Duncan
 
Posts: n/a

Default Name filter problem when name has ' in it - 09-07-2011 , 04:01 AM






This is the coding for a name search that filters the details.
It works well but while John Smith is fine John O'Smith is a problem.
Is there another way

Private Sub CboSearch_AfterUpdate()
Dim strFilter As String

'decide what values are in the filter boxes
If Me.CboSearch <> "" Then
'if first filter not blank, filter by Name
strFilter = Me.CboSearch
DoCmd.ApplyFilter , "Name = '" & strFilter & "'"
Else
'if both filters blank, don't turn on filter
Me.FilterOn = False
End If
Me.Refresh
Me.btnApply.SetFocus
End Sub

Reply With Quote
  #2  
Old   
Stuart McCall
 
Posts: n/a

Default Re: Name filter problem when name has ' in it - 09-07-2011 , 04:13 AM






"Duncan" <duncanjx (AT) optusnet (DOT) com.au> wrote

Quote:
This is the coding for a name search that filters the details.
It works well but while John Smith is fine John O'Smith is a problem.
Is there another way

Private Sub CboSearch_AfterUpdate()
Dim strFilter As String

'decide what values are in the filter boxes
If Me.CboSearch <> "" Then
'if first filter not blank, filter by Name
strFilter = Me.CboSearch
DoCmd.ApplyFilter , "Name = '" & strFilter & "'"
Else
'if both filters blank, don't turn on filter
Me.FilterOn = False
End If
Me.Refresh
Me.btnApply.SetFocus
End Sub
Try:

DoCmd.ApplyFilter , "Name = " & Chr(34) & strFilter & Chr(34)

Or you could double-up the single quote:

strFilter = Replace(strFilter, "'", "''")

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.