SQL = ". .like '" & Mike's Garage & "*'"

Posted on 1998-11-19
Last Modified: 2006-11-17
Variable = "Mike's Garage"
SQL = " '" & Variable & "*'". . the variable used contains a possesive "Mike's" which fouls up the SQL statement because of the apostrophe.  How can I parse this out so the SQL looks for the record, since the record says "Mike's Garage" not "Mikes Garage".  The SQL statement, because of the apostrophe in the name, stops at 'Mike' looking for an operator.  help help.
Question by:RUSTY
  • 4
  • 3

Author Comment

ID: 1445660
Edited text of question

Author Comment

ID: 1445661
Edited text of question

Author Comment

ID: 1445662
Edited text of question
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

LVL 18

Accepted Solution

deighton earned 30 total points
ID: 1445663
instead of the ' use ''
LVL 18

Expert Comment

ID: 1445664
'Heres a function to put in the extra ' where it is needed

Private Function boggle(s As String) As String

    Dim stemp As String
    Dim c As Integer

   For c = 1 To Len(Text1)
 If Mid(Text1, c, 1) = "'" Then        'NB the "'" is <double quote><single Qt><dbl quote>
            stemp = stemp & "'"      'quote sequence as above
        End If
        stemp = stemp & Mid(Text1, c, 1)
    boggle = stemp

End Function

LVL 18

Expert Comment

ID: 1445665
I need to be clearer because of the way it looks on screen where you have say

O'Brien you must change the ' to two adjacent single quotes i.e ' followed by ' (rather than double quotes)  my function boggle does this for you, once youve boggled your string use it in your sql.

Author Comment

ID: 1445666

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
I need help formating a date variable in my VB.Net application 2 61
Updates not working for MS Windows 7 12 183
MsgBox 2 59
Determine Range to Select 5 53
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

830 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