Thank you for your explanation. I wrote a routine to create the sql string
like this:
----------------------------------------------------------------------------------------------
Public Function SearchForm(strmainform, strTabSource)
strMid = ""
strKrit = ""
strSQL = ""
Set db = DBEngine(0)(0)
Dim rs As Recordset
Dim tempDate As String
Dim ystrSQL As String
Dim xstrSQL As String
ystrSQL = "select * from "
ystrSQL = ystrSQL & strTabSource & " "
'xstrSQL check SQL string to see if data has been found
xstrSQL = ystrSQL
Dim k As Integer
Dim tempCounter As Integer
tempCounter = 0
Dim counter As Integer
counter = 0
Dim tempStr As String
'select fields with tag 1 or 2, 1 for data and 2 for date format
'check if data is entered, no data ---> counter = 0, data entry yes ---->
counter > 0
tempCounter = 0
For k = 0 To Forms(strmainform).Controls.Count - 1
If Forms(strmainform).Controls(k).Tag = 1 Or
Forms(strmainform).Controls(k).Tag = 2 Or Forms(strmainform).Controls(k).Tag
= 3 Then
If Forms(strmainform).Controls(k) <> "" Then
counter = counter + 1
End If
End If
Next k
If counter > 0 Then
ystrSQL = ystrSQL & "where "
Else
'Dim Msg, Style, Title, Help, Ctxt, Response, MyString
'Msg = "No entries! Please enter data." ' Define message.
'Style = vbInformation ' Define buttons.
'Title = "Search Result" ' Define title.
'Help = "DEMO.HLP" ' Define Help file.
'Ctxt = 1000 ' Define topic
' context.
' Display message.
'Response = MsgBox(Msg, Style, Title, Help, Ctxt)
End If
For k = 0 To Forms(strmainform).Controls.Count - 1
If Forms(strmainform).Controls(k).Tag = 1 Or
Forms(strmainform).Controls(k).Tag = 2 Or Forms(strmainform).Controls(k).Tag
= 3 Then
If Forms(strmainform).Controls(k) <> "" Then
tempCounter = tempCounter + 1
strMid = ""
'evaluate numerical, date, text
strDataFlag = 0
'1 = numerical (0...9)
'2 = date (07/25/2007)
'3 = text (A....Z, 0....9)
'4 = ...
If Forms(strmainform).Controls(k).Tag = 1 Then
strDataFlag = 1 'H001, T001...
ElseIf Forms(strmainform).Controls(k).Tag = 2 Then
strDataFlag = 2 'date 07/25/2007
ElseIf Forms(strmainform).Controls(k).Tag = 3 Then
strDataFlag = 3 'text
End If
strKrit = Forms(strmainform).Controls(k)
strLen = Len(strKrit)
'evaluate strMid for SQL query
'option strMid definition
' case -----> strMid
' nothing -----> "="
' "<>" -----> "IS NOT"
' ">" -----> ">"
' "<" -----> "<"
' ">0" -----> "LIKE"
' "*" -----> "LIKE"
strLen = Len(strKrit)
If Left(strKrit, 2) = "<>" Then 'And Len(strKrit) > 2 Then
strMid = "<>"
strLen = Len(strKrit) - 2
strKrit = Right(strKrit, strLen)
MsgBox ("strKrit : " & strKrit)
'check and convert to sql date US American format
If strDataFlag = 2 Then
strKrit = sqlDate(strKrit)
ElseIf strDataFlag = 1 Then
'nothing, don't include them into SQL string
ElseIf strDataFlag = 3 Then
'...to follow
End If
ystrSQL = ystrSQL &
Forms(strmainform).Controls(k).Name & strMid & " " & strKrit
ElseIf Left(strKrit, 1) = "<" And Len(strKrit) > 1 Then
strMid = "<"
strLen = Len(strKrit) - 1
strKrit = Right(strKrit, strLen)
'check and convert to sql date US american format
If strDataFlag = 2 Then
strKrit = sqlDate(strKrit)
ElseIf strDataFlag = 1 Or strDataFlag = 3 Then
'nothing
End If
ystrSQL = ystrSQL &
Forms(strmainform).Controls(k).Name & " " & strMid & " " & strKrit
ElseIf Left(strKrit, 1) = ">" And Len(strKrit) > 1 Then
strMid = ">"
strLen = Len(strKrit) - 1
strKrit = Right(strKrit, strLen)
'check and convert to sql date US american format
If strDataFlag = 2 Then
strKrit = sqlDate(strKrit)
ElseIf strDataFlag = 1 Or strDataFlag = 3 Then
'nothing
End If
ystrSQL = ystrSQL &
Forms(strmainform).Controls(k).Name & strMid & " " & strKrit
ElseIf Left(strKrit, 1) = "*" And Len(strKrit) = 1 Then
strMid = "LIKE"
strLen = Len(strKrit) - 1
strKrit = "'*'"
'check and convert to sql date US american format
'no conversion needed '*' does the job
'If strDataFlag = 1 Then
' strKrit = sqlDate(strKrit)
'ElseIf strDataFlag = 0 Then
' 'nothing
'End If
ystrSQL = ystrSQL &
Forms(strmainform).Controls(k).Name & " " & strMid & " " & strKrit
ElseIf Right(strKrit, 1) = "*" And Len(strKrit) > 1 Then
'MsgBox (Right(strKrit, 1))
strMid = "LIKE"
strKrit = Left(strKrit, strLen - 1)
strKrit = "'" & strKrit & "*" & "'"
ystrSQL = ystrSQL &
Forms(strmainform).Controls(k).Name & " " & strMid & " " & strKrit
Else:
strMid = " = "
If strDataFlag = 2 Then
'strKrit = sqlDate(strKrit)
ElseIf strDataFlag = 1 Then
'nothing
ElseIf strDataFlag = 3 Then
strKrit = "'" & strKrit & "'"
End If
ystrSQL = ystrSQL &
Forms(strmainform).Controls(k).Name & strMid & " " & strKrit
End If
If tempCounter < counter Then
ystrSQL = ystrSQL & " AND "
Else: 'nothing ystrSQL = ystrSQL & ";"
' ystrSQL = ystrSQL & ";"
End If
End If
Else
'nothing
End If
strKrit = ""
Next k
'strSQL = ystrSQL & ";"
ystrSQL = ystrSQL & " AND inactive = false"
strSQL = ystrSQL & ";"
'''''''''''''''''''''''''''''''''''MsgBox ("Final SQL: " & strSQL)
'strSQL = "Select * from tabTripHeader where Date = #7/24/2007#;" 'to be
deleted - trial
On Error GoTo err_handler
'MsgBox (strSQL)
Set rs = db.OpenRecordset(strSQL, DB_OPEN_DYNASET)
If rs.RecordCount > 0 And xstrSQL <> ystrSQL Then
Forms(strmainform).RecordSource = strSQL
Call AttachForm(strmainform, strSQL)
Call bind(strmainform)
Else
' MsgBox ("No matches - please refine search"), vbInformation
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "No search results, please narrow your search" ' Define message.
Style = vbInformation ' Define buttons.
Title = "Search Result" ' Define title.
Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
'If Response = vbYes Then ' User chose Yes.
' MyString = "Yes" ' Perform some action.
'Else ' User chose No.
' MyString = "No" ' Perform some action.
'End If
End If
err_handler:
End Function
---------------------------------------------------------------------------------------
Is this the right way forward? I still find it's quite a bit of code for a
small thing like full screen text search. Isn't there an easier way? I kind
of like the approach of unbound forms as it speeds up access to tremendously
especially in a wlan environment.
Would you know by any chance how access works when using permanently linked
forms? Does access download all the table content or just what you see on the
screen?