Solved

Wildcard find includes an apostrophe - vb6 & Access97

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

760 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

18 Experts available now in Live!

Get 1:1 Help Now