V
Veus
Hi,
Im trying to allow it so users can search records using < and > for the
date fields.
The search form works fine with = values however when i enter < or >
followed by a date
( < 28/04/06 for example ) it comes up with a syntax error. Ive printed
the debug for the string strWhere:
([name] Like "**") AND ([lastBookDate] = <25/04/06) AND
My code for the processing of this is:
Dim strWhere As String 'The criteria string.
Dim lngLen As Long
Dim strCapture As String
Const conJetDate = "\#mm\/dd\/yyyy\#"
If Not IsNull(Me.lastBookDate) Then
strCapture = Left(Me![lastBookDate], 2)
If strCapture = "> " Then
strWhere = strWhere & "([lastBookDate] > " &
Format(Me.Controls("lastBookDate"), conJetDate) & ") AND "
ElseIf strCapture = "<" Then
strWhere = strWhere & "([lastBookDate] < " &
Format(Me.Controls("lastBookDate"), conJetDate) & ") AND "
ElseIf strCapture = ">=" Then
strWhere = strWhere & "([lastBookDate] >= " &
Format(Me.Controls("lastBookDate"), conJetDate) & ") AND "
ElseIf strCapture = "<=" Then
strWhere = strWhere & "([lastBookDate] <= " &
Format(Me.Controls("lastBookDate"), conJetDate) & ") AND "
Else
strWhere = strWhere & "([lastBookDate] = " &
Format(Me.Controls("lastBookDate"), conJetDate) & ") AND "
End If
Debug.Print strWhere
End If
As you can see it automatically puts in an equals sign when I dont want
it, so this results in the syntax error ( = <28/04/06 isnt correct)
Are my if else statements setup correctly and also have i missed
something extremely obvious?
Thanks in advance.
Im trying to allow it so users can search records using < and > for the
date fields.
The search form works fine with = values however when i enter < or >
followed by a date
( < 28/04/06 for example ) it comes up with a syntax error. Ive printed
the debug for the string strWhere:
([name] Like "**") AND ([lastBookDate] = <25/04/06) AND
My code for the processing of this is:
Dim strWhere As String 'The criteria string.
Dim lngLen As Long
Dim strCapture As String
Const conJetDate = "\#mm\/dd\/yyyy\#"
If Not IsNull(Me.lastBookDate) Then
strCapture = Left(Me![lastBookDate], 2)
If strCapture = "> " Then
strWhere = strWhere & "([lastBookDate] > " &
Format(Me.Controls("lastBookDate"), conJetDate) & ") AND "
ElseIf strCapture = "<" Then
strWhere = strWhere & "([lastBookDate] < " &
Format(Me.Controls("lastBookDate"), conJetDate) & ") AND "
ElseIf strCapture = ">=" Then
strWhere = strWhere & "([lastBookDate] >= " &
Format(Me.Controls("lastBookDate"), conJetDate) & ") AND "
ElseIf strCapture = "<=" Then
strWhere = strWhere & "([lastBookDate] <= " &
Format(Me.Controls("lastBookDate"), conJetDate) & ") AND "
Else
strWhere = strWhere & "([lastBookDate] = " &
Format(Me.Controls("lastBookDate"), conJetDate) & ") AND "
End If
Debug.Print strWhere
End If
As you can see it automatically puts in an equals sign when I dont want
it, so this results in the syntax error ( = <28/04/06 isnt correct)
Are my if else statements setup correctly and also have i missed
something extremely obvious?
Thanks in advance.