Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Wildcard find includes an apostrophe - vb6 & Access97

Posted on 2000-02-24
4
Medium Priority
?
383 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 660 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

972 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