Data type mismatch in criteria expression.
Hey guys,
I was hoping you can help me. I'm building a site for a real estate company. They want to search for houses for sale on a database. Multiple fields will be used in the search. The client may leave some fields empty during search.
This is the best I was able to come up with, but I get "Data type mismatch in criteria expression." error when the the fields are filled.
Dim PropertyCode, CityCode, StartPrice, EndPrice, MinBeds, MinBaths, MinBSF, MinAcres, YearBuilt
PropertyCode = Request("PropertyCode")
CityCode = Request("CityCode")
CityCode = Replace(CityCode, ", ", "','")
StartPrice = Request("StartPrice")
EndPrice = Request("EndPrice")
MinBeds = Request("MinBeds")
MinBaths = Request("MinBaths")
MinBSF = Request("MinBSF")
MinAcres = Request("MinAcres")
YearBuilt = Request("YearBuilt")
sql="SELECT * FROM Midfl_data WHERE PropertyCode = '" & PropertyCode & "' AND CityCode IN ('" & CityCode & "')"
If Request("StartPrice") = "0" Then
Else
sql = sql & "AND Price >= '" & StartPrice & "'"
End If
If Request("EndPrice") = "99999999999" Then
Else
sql = sql & "AND Price <= '" & EndPrice & "'"
End If
If Request("MinBeds") = "0" Then
Else
sql = sql & "AND Bedrooms >= '" & MinBeds & "'"
End If
If Request("MinBaths") = "0" Then
Else
sql = sql & "AND Bathrooms >= '" & MinBaths & "'"
End If
If Request("MinBSF") = "0" Then
Else
sql = sql & "AND BuildingSquareFeet >= '" & MinBSF & "'"
End If
If Request("MinAcres") = "0" Then
Else
sql = sql & "AND Acres >= '" & MinAcres & "'"
End If
If Request("YearBuilt") = "0" Then
Else
sql = sql & "AND YearBuilt >= '" & YearBuilt & "'"
End If
sql = sql & "Order by Price"
rs.open sql, oConn, 1, 1
P.S. I've found that if I insert the code for each field choice in the sql statement that the result page only pulls records that have data in these fields. Some records may have some fields empty. So if a customer leaves out a field I need it to pull record not just the ones with some data.
Thank you guys for any help you can provide.
|