Solved

Wildcard find includes an apostrophe - vb6 & Access97

Posted on 2000-02-24
4
359 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now