Forum Moderators: open

Message Too Old, No Replies

How to search by date range - ASP & MS Access

Cannot get the code to work

         

hazardtomyself

11:45 pm on Apr 2, 2003 (gmt 0)

10+ Year Member



I have an online search page where I can search a MS Access database via ASP. I have several fields and am searching using the WhereClause. I want to add a "search by date range" function and cannot figure out the code. A snippet of code on the results page is as follows:

WhereClause = "WHERE "
If Name <> "" Then
WhereClause = WhereClause & "(Name LIKE '%" & Name & "%') AND "
End If
If LastName <> "" Then
WhereClause = WhereClause & "(LastName LIKE '%" & LastName & "%') AND "
End If
If Email <> "" Then
WhereClause = WhereClause & "InStr(Email,'" & _
Email & "')>0 AND "
End If
If Address <> "" Then
WhereClause = WhereClause & "InStr(Address,'" & _
Address & "')>0 AND "
End If
If City <> "" Then
WhereClause = WhereClause & "InStr(City,'" & _
City & "')>0 AND "
End If

'You get the jist. I am trying to add search by date range. I want to bring up all record within the date range input. I know that the fomat the user inputs is critical.

"This code does not work.
If PostedFrom = "" And PostedTo <> "" Then
PostedFrom = "00/00/0000"
ElseIf PostedFrom <> "" And PostedTo = "" Then
PostedTo = "12/31/3000"
End If
If PostedFrom <> "" And PostedTo <> "" Then
WhereClause = WhereClause & "Posted >= " & _
PostedFrom & " AND Posted <= " & _
PostedTo & " AND "
End If

If I am not clear I will supply the search page. Thank you.

txbakers

12:41 am on Apr 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



With Dates in MS Access you need to enclose them in hask marks:

Where myDate between #1/1/2003# and #3/30/2003#

hazardtomyself

1:31 am on Apr 3, 2003 (gmt 0)

10+ Year Member



I know MS Access dates need to be bound by the # but I cannot figure out where to put them in the WhereClause.

Woz

1:53 am on Apr 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PostedFrom = "#00/00/0000#"
ElseIf PostedFrom <> "" And PostedTo = "" Then
PostedTo = "#12/31/3000#"

etc

Onya
Woz

paladin

2:42 am on Apr 5, 2003 (gmt 0)

10+ Year Member



try:
rs="select * from myTable where myDate between #" & date1 & "# and #" & date2 & "#"