Bagbones
Messages postés11Date d'inscriptionmercredi 19 juin 2002StatutMembreDernière intervention 1 mars 2008
-
26 juin 2002 à 08:25
pingwee
Messages postés26Date d'inscriptiondimanche 30 décembre 2001StatutMembreDernière intervention19 avril 2003
-
28 juin 2002 à 16:45
Bonjour,
je tente désespérement de passer un argument contenant un apostrophe à une requête SQL, mais ca plante (opérateur absent), voila l'un des codes que j'ai essayé :
If (Princ.Combo17.Text <> "") Then
std = DoubleCote(Princ.Combo17.Text)
Set mag = New Recordset
mag.Open "select telemag from magasins where Region ='" & _
Princ.Combo16.Text & "' and Villemag ='" & Princ.Combo15.Text & _
"' and Adressemag =" & std, conmag, adOpenDynamic
' A noter que depuis VB6 un simple Replace( stTXT, "'", "''") suffit.
Public Function DoubleCote(ByVal stTXT As String) As String
' Reçoit une chaîne et double les apostrophes qui se trouvent à l'intérieur...
Dim lgPos As Long
Dim stTMP As String
stTMP = stTXT
' On cherche la position dans la chaîne de la première apostrophe
lgPos = InStr(stTMP, "'")
' Tant qu'il y a des apostrophes dans la chaîne...
Do While lgPos > 0
' Chaîne = début de la chaîne (apostrophe comprise) + "'" + fin de la chaîne
stTMP = Left$(stTMP, lgPos) & "'" & Right$(stTMP, Len(stTMP) - lgPos)
' On cherche la position de l'apostrophe suivante
lgPos = InStr(lgPos + 2, stTMP, "'")
Loop
' Renvoie la chaîne modifiée
DoubleCote = Trim(stTMP)
End Function
voila, je sais qu'il faut remplaceer l'apostrophe par une double apostrophe, et c'est ce que fait trés bien cette fonction, mais ma requête plante quand même, alors QUID?
nariel1
Messages postés55Date d'inscriptionmardi 21 mai 2002StatutMembreDernière intervention 6 mai 2009 26 juin 2002 à 09:57
essaye plutot ca
Public Function CheckForQuote(str As String)
If str = "" Then
CheckForQuote = ""
Exit Function
End If
Dim lPos As Long
Dim slPos1 As Long
lPos = 1
Do While lPos <> 0
slPos1 = InStr(lPos, str, "'")
If slPos1 > 0 Then
str = Mid(str, 1, slPos1) & "'" & _
Mid(str, slPos1 + 1, Len(str) - slPos1)
lPos = InStr(slPos1 + 1, str, "'") + 1
Else
lPos = 0
End If
Loop
CheckForQuote = str
End Function
nariel1