1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| Sub test()
Dim strSQL As String, strChaine As String, tstrT() As String
Dim i As Integer
'Début de la requete
strSQL = "SELECT * FROM Matable"
'Chaine à traiter
strChaine = "Salut m'sieur"
'Recupère la liste des mots
tstrT = Split(Replace(strChaine, "'", " "), " ")
'Parcours le tableau et construit la requete
For i = 0 To UBound(tstrT)
'Si premier critere alors ajoute le where
If i = 0 Then
strSQL = strSQL & " WHERE "
Else
strSQL = strSQL & " OR "
End If
'Ajoute le critere
strSQL = strSQL & " MonChamp LIKE *" & tstrT(i) & "*"
Next i
MsgBox strSQL
End Sub |
Partager