Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Query String

Posted on 2001-06-27
3
Medium Priority
?
299 Views
Last Modified: 2010-05-02
Hi,

I have this problem.

when i made a SQL string query example:

set rst = new recordset
rst.open "select * from table where field = 'ABC'", ConnStr, adOpenStatic, adLockReadOnly

Note that the criteria "ABC" is retrieved from user input. The qns is, if the user input "AB'C", my query string will have error as the string will end till "AB" and the other statements will be invalid.

How am i going to resolve this?
Is there any other special characters which will caused this problem?

Pls help!
0
Comment
Question by:edonasan
[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
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 300 total points
ID: 6231066
You just need to double the ' character:

MyString = "AB'C"
rst.Open "Select * From Table Where Field = '" & Replace(MyString,"'","''") & "'",ConnStr,adOpenStatic,adLockReadOnly

0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6231123
Hi edonasan, TimCottee is correct.

Here is an alternative sample , use it as you use VB6 lower:

______________________________________________

Private Function Convert(ByVal Keyword As String) As String
   EmptyM = Keyword
   Do While InStr(EmptyM, "'") <> 0
       i = InStr(EmptyM, "'")
       EmptyM = Right$(Keyword, Len(Keyword) - i)
       Keyword = Left(Keyword, i) & "'" & EmptyM
   Loop
   Convert = Keyword
End Function

Use like this:
MyString = "AB'C"
rst.Open "Select * From Table Where Field = '" & Convert(MyString) & "'",ConnStr,adOpenStatic,adLockReadOnly
0
 

Author Comment

by:edonasan
ID: 6231138
yes!
thanks TimCotte!

Thanks ryancys too, i hope to allocate some points to u too.. thanks again :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
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…
Suggested Courses

618 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