I have a form with several text boxes which are used to build a search filter. I have used this many times and it works perfectly. However I have a need to allow the user to search for a value that is >= to an entered amount and I cant get the correct syntax in the code.
The code (apologies that I can't remember who posted it originally) is the following.
Private Function BuildFilter() As Variant
Dim varWhere As Variant
varWhere = Null
If Me.qExpID > "" Then
varWhere = varWhere & "[ExpID] LIKE """ & Me.qExpID & "*"" And "
End If
If Me.qDateF > "" Then
varWhere = varWhere & "[Date] >=#" & Format(Me.qDateF, "yyyy-mm-dd") & "# And "
End If
If Me.qDateT > "" Then
varWhere = varWhere & "[Date] <=#" & Format(Me.qDateT, "yyyy-mm-dd") & "# And "
End If
If Me.qVendor > "" Then
varWhere = varWhere & "[Vendor] LIKE """ & Me.qVendor & "*"" And "
End If
If Me.qExpCat > "" Then
varWhere = varWhere & "[Exp Category] LIKE """ & Me.qExpCat & "*"" And "
End If
If Me.qExpItem > "" Then
varWhere = varWhere & "[Item] LIKE """ & Me.qExpItem & "*"" And "
End If
If Me.qTransType > "" Then
varWhere = varWhere & "[Trans] LIKE """ & Me.qTransType & "*"" And "
End If
If Me.qTransRef > "" Then
varWhere = varWhere & "[Trans Ref No] LIKE """ & Me.qTransRef & "*"" And "
End If
If Me.qAmount > "" Then
varWhere = varWhere & "[Amount] LIKE """ & Me.qAmount & "*"" And "
End If
If Me.qDocRec > "" Then
varWhere = varWhere & "[Document Receipt] LIKE """ & Me.qDocRec & "*"" And "
End If
' Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "WHERE " & varWhere
' strip off last "AND" in the filter
If Right(varWhere, 5) = " And " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
End Function
The field I need the >= search for is [Amount]
Could someone please advise if this is possible or do I need to start afresh with something completely different.
Thanks
Smalty
The code (apologies that I can't remember who posted it originally) is the following.
Private Function BuildFilter() As Variant
Dim varWhere As Variant
varWhere = Null
If Me.qExpID > "" Then
varWhere = varWhere & "[ExpID] LIKE """ & Me.qExpID & "*"" And "
End If
If Me.qDateF > "" Then
varWhere = varWhere & "[Date] >=#" & Format(Me.qDateF, "yyyy-mm-dd") & "# And "
End If
If Me.qDateT > "" Then
varWhere = varWhere & "[Date] <=#" & Format(Me.qDateT, "yyyy-mm-dd") & "# And "
End If
If Me.qVendor > "" Then
varWhere = varWhere & "[Vendor] LIKE """ & Me.qVendor & "*"" And "
End If
If Me.qExpCat > "" Then
varWhere = varWhere & "[Exp Category] LIKE """ & Me.qExpCat & "*"" And "
End If
If Me.qExpItem > "" Then
varWhere = varWhere & "[Item] LIKE """ & Me.qExpItem & "*"" And "
End If
If Me.qTransType > "" Then
varWhere = varWhere & "[Trans] LIKE """ & Me.qTransType & "*"" And "
End If
If Me.qTransRef > "" Then
varWhere = varWhere & "[Trans Ref No] LIKE """ & Me.qTransRef & "*"" And "
End If
If Me.qAmount > "" Then
varWhere = varWhere & "[Amount] LIKE """ & Me.qAmount & "*"" And "
End If
If Me.qDocRec > "" Then
varWhere = varWhere & "[Document Receipt] LIKE """ & Me.qDocRec & "*"" And "
End If
' Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "WHERE " & varWhere
' strip off last "AND" in the filter
If Right(varWhere, 5) = " And " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
End Function
The field I need the >= search for is [Amount]
Could someone please advise if this is possible or do I need to start afresh with something completely different.
Thanks
Smalty