Solved

Wildcard find includes an apostrophe - vb6 & Access97

Posted on 2000-02-24
4
368 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
[X]
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
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

623 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