Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Wildcard find includes an apostrophe - vb6 & Access97

Posted on 2000-02-24
4
362 Views
Last Modified: 2012-08-14
How do I perform a wildcard find for a string that includes an apostrophe.  For example, I can perform a find on Megan's ball and retrieve the correct record.  But not on Megan's*.  I know it has to do with using both single and double quotes in the same sql.  I want co
0
Comment
Question by:foltz
  • 2
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
deighton earned 165 total points
ID: 2554411
Double up the apostrophe (use two in place of 1)

like 'Megan''s*'
0
 

Author Comment

by:foltz
ID: 2554483
Thank you
0
 
LVL 18

Expert Comment

by:deighton
ID: 2554526
Set rs = db.OpenRecordset("select * from customerdetails where CustCurrSurname like 'Blogg''s*'", dbOpenSnapshot)


'Heres how to do it with code using a find_n_replace function

Private Sub Command1_Click()
MsgBox strFind_n_Replace("fred blogg's", Chr(39), Chr(39) + Chr(39))
End Sub


Public Function strFind_n_Replace(ByVal strTarget, strFind, strReplaceWith)
'--------------------------------------------------------------------
'Description    :  A true find_n_replace function.
'               :
'Created By     :  A.J.Deighton
'Create Date    : 18/02/00
'
'Inputs         : string,string,string
'Outputs        : <None>
'Returns        : string
'--------------------------------------------------------------------


    Dim lngCursor As Long
    Dim lngPos As Long
    Dim lngLen1 As Long, lngLen2 As Long
   
    If Len(strTarget) = 0 Or Len(strFind) = 0 Then
   
        strFind_n_Replace = strTarget
       
        Exit Function
       
    End If
   
    lngLen1 = Len(strFind)
    lngLen2 = Len(strReplaceWith)
   
    lngCursor = 1
    lngPos = InStr(lngCursor, strTarget, strFind)
   
    Do Until lngPos = 0
   
        strTarget = Left(strTarget, lngPos - 1) & strReplaceWith _
                    & Mid(strTarget, lngPos + lngLen1)
                   
        lngCursor = lngPos + lngLen2
       
        lngPos = InStr(lngCursor, strTarget, strFind)
       
    Loop
   
    strFind_n_Replace = strTarget

End Function
0
 

Author Comment

by:foltz
ID: 2554622
I think you're the greatest!!!!!  How can I give you bonus points for the code.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question