Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete all records when date has passed

Status
Not open for further replies.

ukwebsite

Programmer
Dec 9, 2000
82
GB
I have a site that uses MS Access. People add records to the database including a date, dd/mm/yyyy format. All I want to do is run a statement that will delete all records where the date that the user entered is past.

I keep getting this message

Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
/delete1.asp, line 38


This is my current code although it is a bit of a mess. Please help.

Thanks

Matthew Wilde
matthew@ukwebsite.com



<%@ LANGUAGE=&quot;VBScript&quot; %>
<%
Option Explicit
Response.Expires = 0
Session.LCID = 2057
%>
<!-- #INCLUDE FILE=&quot;adovbs.inc&quot; -->
<%
Dim lngRecsAffected
Dim cnnFormToDB
Dim DateOfEvent, strType, strQ, objRS, objConn, sConnString

if Request.ServerVariables(&quot;QUERY_STRING&quot;) <> &quot;&quot; Then
DateOfEvent = cdate(Date)
strType = Request.QueryString(&quot;Type&quot;)
%>

<html><body>
<%
Set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
sConnString = &quot;DRIVER={Microsoft Access Driver (*.mdb)};&quot; & _
&quot;DBQ=&quot; & Server.MapPath(&quot;/Database/tickets.mdb&quot;) & &quot;;&quot;
objConn.Open(sConnString)
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
strQ = &quot;&quot;
strQ = strq & &quot;DELETE FROM concerts WHERE DateOfEvent = &quot;
strQ = strQ & &quot;'&quot; & DateOfEvent & &quot;'&quot;
strQ = strQ & &quot;;&quot;
objConn.Execute strQ
objConn.Close
Set objConn = Nothing
%>


<font face=Arial size=2><b>
<H2>All records before <%= DateOfEvent %> have been deleted!</H2>
<font face=Arial size=2><b>
<P>
<B>If you spelt the record name correct - please check to see if the record has gone</B><br><br>
<p><font size=&quot;2&quot; face=&quot;Arial&quot;><a href=&quot;../<%= strType %>/index.asp&quot;><b>View Results</b></a></font></p>
</P>
</body></html>
<%
Else
%>
<html><body>
DELETE todays date is <%= date %><BR>
<Form action=&quot;<% Request.ServerVariables(&quot;SCRIPT_NAME&quot;) %>&quot; METHOD=&quot;GET&quot;>
<p><select size=&quot;1&quot; name=&quot;Type&quot;>
<option value=&quot;Concerts&quot;>Concerts</option>
</select>
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;submit form&quot;>
</form>
</body></html>
<% end if %>
 
I have solved it.

For anyone else who has this problem it was because I used

strQ = strQ & &quot;'&quot; & DateOfEvent & &quot;'&quot;

which would have worked if was using SQL but I am using access and should have used

strQ = strQ & &quot;#&quot; & DateOfEvent & &quot;#&quot;
Matthew Wilde
matthew@ukwebsite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top