Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Single quote in a where clause

Hi
2 simple functions:

Function adhHandleQuotes(ByVal varValue As Variant, ByVal
strDelimiter As String) As Variant

' Replace all instances of strdelimiter with varValue
with TWO instances,
' thereby handling the darned quote issue once and
for all.

' Returns Null if varValue was Null, otherwise
' returns varValue with all instances of strDelimiter
' replaced with two of each.
' adhHandleQuotes("This 'is' a test", "'") returns
' "This ''is'' a test"

adhHandleQuotes = adhReplace(varValue, strDelimiter,
strDelimiter & strDelimiter)
End Function

Function adhReplace(ByVal varValue As Variant, ByVal
strFind As String, ByVal strReplace As String) As Variant

' Replace all instances of strFind with strReplace in
varValue.

Dim intLenFind As Integer
Dim intLenReplace As Integer
Dim intPos As Integer

If IsNull(varValue) Then
adhReplace = Null
Else
intLenFind = Len(strFind)
intLenReplace = Len(strReplace)

intPos = 1
Do
intPos = InStr(intPos, varValue, strFind)
If intPos 0 Then
varValue = Left(varValue, intPos - 1) &
strReplace & Mid(varValue, intPos + intLenFind)
intPos = intPos + intLenReplace
End If
Loop Until intPos = 0
End If
adhReplace = varValue
End Function


-----Original Message-----

The SQL where clause fails because variableType has a

value that contains a single quote. Using amber signs and
double quotes worked in VB 6.0.

variableType = A'DVANCE

Sql = "Select Type From Equipment"
Sql = Sql & "WHERE Type = '" & variableType & "'

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert single quote symbol Gotroots Excel Worksheet Functions 9 November 3rd 09 02:03 PM
vlookup and using single quote Bishop Excel Worksheet Functions 2 April 3rd 09 06:02 PM
How do I display a single quote in a cell? Brotha B Excel Discussion (Misc queries) 1 August 17th 07 02:09 AM
using a single quote ' in SEARCH function ExTexan Excel Worksheet Functions 2 December 30th 06 01:11 PM
Remove single quote Avadivelan TCS Excel Worksheet Functions 4 October 5th 06 03:48 PM


All times are GMT +1. The time now is 12:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"