copy & paste the next function to your application
use it al followed:
Dim SQL$
Dim rs as recordset
Dim db as database
Set db = OpenDatabase(yourdatabase)
SQL$ = "SELECT * FROM " & yourdatabase
SQL$ = SQL$ & MakeSQLString(Text1.text,"title")
Set rs = db.OpenRecordset(SQL$)
In the Textbox you can put your searchwords. If you want to use AND / OR (or anything
else that you like but don't forget to specify it in the code!) If you put just words
without a separator than the AND is used.
----------- code -------------
Function MakeSQLString(bron$, vField$)
Dim p, l_counter%, t%
Dim TempBron$, tempdata$
Dim criteria() As String
Dim lastCriteria As Boolean
TempBron$ = bron$
t% = 0
For l_counter% = 1 To Len(bron$)
p = InStr(TempBron$, Chr(32))
If p <> 0 Then
ReDim Preserve criteria(t%)
criteria(t%) = Left$(TempBron$, p - 1)
TempBron$ = Right$(TempBron$, Len(TempBron$) - p)
t% = t% + 1
l_counter% = l_counter% + p
End If
Next l_counter%
ReDim Preserve criteria(t%)
criteria(t%) = TempBron$
lastCriteria = True
tempdata$ = " WHERE "
For l_counter% = 0 To t%
Select Case criteria(l_counter%)
Case "EN", "en", "AND", "and", "+"
tempdata$ = tempdata$ & " AND "
lastCriteria = True
Case "OF", "of", "OR", "or"
tempdata$ = tempdata$ & " OR "
lastCriteria = True
Case Else
If Not lastCriteria Then
tempdata$ = tempdata$ & " AND ( " & vField$ & " LIKE '*" & criteria(l_counter%) & "*') "
Else
tempdata$ = tempdata$ & "( " & vField$ & " LIKE '*" & criteria(l_counter%) & "*') "
lastCriteria = False
End If
End Select
Next l_counter%
MakeSQLString = tempdata$
End Function
Return