I have a form with several text boxes into which I enter search criteria which will be applied to a query that in turn will update a form based on the result of the query.
All of the boxes are working fine except the one where I enter a date value in 'short date format ie 06/01/2011', and I want the result to be greater than or equal to this date.
The text box is qdte which updates field PriceFrom. This forms pat of a filter. I am using code:
Private Function BuildFilter() As Variant
Dim varWhere As Variant
varWhere = Null
If Me.qdte > "" Then
varWhere = varWhere & "[PriceFrom] >= " & Format(Me.qdte, "dd-mm-yyyy") & " AND "
End If
If Me.qprtr > "" Then
varWhere = varWhere & "[Printer] LIKE """ & Me.qprtr & "*"" AND "
End If
If Me.qpsize > "" Then
varWhere = varWhere & "[PaperSize] LIKE """ & Me.qpsize & "*"" And "
End If
If Me.qlam > "" Then
varWhere = varWhere & "[Laminate] LIKE """ & Me.qlam & "*"" And "
End If
If Me.qnofpages > "" Then
varWhere = varWhere & "[NoOfPages] LIKE """ & Me.qnofpages & "*"" And "
End If
If Me.qptype > "" Then
varWhere = varWhere & "[PaperType] LIKE """ & Me.qptype & "*"" And "
End If
If Me.qpweight > "" Then
varWhere = varWhere & "[PaperWeight] LIKE """ & Me.qpweight & "*"" And "
End If
If Me.qqty > "" Then
varWhere = varWhere & "[Quantity] LIKE """ & Me.qqty & "*"" 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
It's the first part of the filter referring to Me.qdte that doesn't work. I have tried many other variations of the syntax without success. I either get a syntax error or a runtime error.
Any suggestions would be much appreciated
Smalty
All of the boxes are working fine except the one where I enter a date value in 'short date format ie 06/01/2011', and I want the result to be greater than or equal to this date.
The text box is qdte which updates field PriceFrom. This forms pat of a filter. I am using code:
Private Function BuildFilter() As Variant
Dim varWhere As Variant
varWhere = Null
If Me.qdte > "" Then
varWhere = varWhere & "[PriceFrom] >= " & Format(Me.qdte, "dd-mm-yyyy") & " AND "
End If
If Me.qprtr > "" Then
varWhere = varWhere & "[Printer] LIKE """ & Me.qprtr & "*"" AND "
End If
If Me.qpsize > "" Then
varWhere = varWhere & "[PaperSize] LIKE """ & Me.qpsize & "*"" And "
End If
If Me.qlam > "" Then
varWhere = varWhere & "[Laminate] LIKE """ & Me.qlam & "*"" And "
End If
If Me.qnofpages > "" Then
varWhere = varWhere & "[NoOfPages] LIKE """ & Me.qnofpages & "*"" And "
End If
If Me.qptype > "" Then
varWhere = varWhere & "[PaperType] LIKE """ & Me.qptype & "*"" And "
End If
If Me.qpweight > "" Then
varWhere = varWhere & "[PaperWeight] LIKE """ & Me.qpweight & "*"" And "
End If
If Me.qqty > "" Then
varWhere = varWhere & "[Quantity] LIKE """ & Me.qqty & "*"" 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
It's the first part of the filter referring to Me.qdte that doesn't work. I have tried many other variations of the syntax without success. I either get a syntax error or a runtime error.
Any suggestions would be much appreciated
Smalty