I have a simple access 2002 database
field: ID (autonum)
field: entered_date (date dd/mm/yyyy)
And want to allow users to select a FROM date (text field using dd/mm/yyyy format) and a TO date (text field using dd/mm/yyyy format)...
The problem Im running into is in passing the variables for the from date and to date in the right format...
when I replace the variables with dates entered directly into the sql statement ( select * from tbl_name where entered_date BETWEEN #1/1/2000# AND #1/1/2003# ) it works fine...
but how can I replace those dates with the variable names and still use the #'s to get this to work... below is the code Im using...
----------------------------------
<%
If request.form("submit" <> "" Then
Dim cnnSimple ' ADO connection
Dim rstSimple ' ADO recordset
Dim strDBPath ' path to our Access database (*.mdb) file
' MapPath of virtual database file path to a physical path.
' If you want you could hard code a physical path here.
strDBPath = Server.MapPath("mydatabase.mdb"
' Create an ADO Connection to connect to the scratch database.
' We're using OLE DB but you could just as easily use ODBC or a DSN.
Set cnnSimple = Server.CreateObject("ADODB.Connection"
' This line is for the Access sample database:
cnnSimple.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
dim varfromdate, vartodate
varfromdate = request.form("dte_from"
vartodate = request.form("dte_to"
' Execute a query using the connection object. It automatically
' creates and returns a recordset which we store in our variable.
On error resume next
Set rstSimple = cnnSimple.Execute("SELECT * FROM tbl_data where entered_date between varfromdate AND vartodate"
if err.number <> "" Then
response.write err.number & " -- Sorry, I found some issue and cant continue..." & vbCrLf
response.write err.description
Response.End()
End If
' Display a table of the data in the recordset. We loop through the
' recordset displaying the fields from the table and using MoveNext
' to increment to the next record. We stop when we reach EOF.
%>
<table border="1">
<%
Do While Not rstSimple.EOF
%>
<tr>
<td><%= rstSimple.Fields("id".Value %></td>
<td><%= rstSimple.Fields("entered_date".Value %></td>
</tr>
<%
rstSimple.MoveNext
Loop
%>
</table>
<%
' Close our recordset and connection and dispose of the objects
rstSimple.Close
Set rstSimple = Nothing
cnnSimple.Close
Set cnnSimple = Nothing
End If%>
__________________________________
field: ID (autonum)
field: entered_date (date dd/mm/yyyy)
And want to allow users to select a FROM date (text field using dd/mm/yyyy format) and a TO date (text field using dd/mm/yyyy format)...
The problem Im running into is in passing the variables for the from date and to date in the right format...
when I replace the variables with dates entered directly into the sql statement ( select * from tbl_name where entered_date BETWEEN #1/1/2000# AND #1/1/2003# ) it works fine...
but how can I replace those dates with the variable names and still use the #'s to get this to work... below is the code Im using...
----------------------------------
<%
If request.form("submit" <> "" Then
Dim cnnSimple ' ADO connection
Dim rstSimple ' ADO recordset
Dim strDBPath ' path to our Access database (*.mdb) file
' MapPath of virtual database file path to a physical path.
' If you want you could hard code a physical path here.
strDBPath = Server.MapPath("mydatabase.mdb"
' Create an ADO Connection to connect to the scratch database.
' We're using OLE DB but you could just as easily use ODBC or a DSN.
Set cnnSimple = Server.CreateObject("ADODB.Connection"
' This line is for the Access sample database:
cnnSimple.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
dim varfromdate, vartodate
varfromdate = request.form("dte_from"
vartodate = request.form("dte_to"
' Execute a query using the connection object. It automatically
' creates and returns a recordset which we store in our variable.
On error resume next
Set rstSimple = cnnSimple.Execute("SELECT * FROM tbl_data where entered_date between varfromdate AND vartodate"
if err.number <> "" Then
response.write err.number & " -- Sorry, I found some issue and cant continue..." & vbCrLf
response.write err.description
Response.End()
End If
' Display a table of the data in the recordset. We loop through the
' recordset displaying the fields from the table and using MoveNext
' to increment to the next record. We stop when we reach EOF.
%>
<table border="1">
<%
Do While Not rstSimple.EOF
%>
<tr>
<td><%= rstSimple.Fields("id".Value %></td>
<td><%= rstSimple.Fields("entered_date".Value %></td>
</tr>
<%
rstSimple.MoveNext
Loop
%>
</table>
<%
' Close our recordset and connection and dispose of the objects
rstSimple.Close
Set rstSimple = Nothing
cnnSimple.Close
Set cnnSimple = Nothing
End If%>
__________________________________