Forum Moderators: open

Message Too Old, No Replies

Inserting dates into access

Driving me up the wall because a / seems to stop it

         

dazj

11:21 pm on Mar 1, 2004 (gmt 0)



I'm sure this has been covered before plenty of times, but I can't find it and this is driving me up the wall...

I'm using the following code to take values from a form and insert them into an access db. They all work fine apart from the date which is a three form values put together. The form values are carried over, but the moment I seperate them with / I get the error as though I'm not using the # to tell access it's a date value - any help most appreciated on this one before my PC goes through the window!

<%
Dim Conn, ConnString
Set Conn = Server.CreateObject("ADODB.Connection")
ConnString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & Server.MapPath("db\gateway.mdb") & ";"
Conn.Open(ConnString)

SQL = "insert into course (Coursename,CourseLocation,CourseDate) values ('" & request("CourseName") & "','" & request("CourseLocation") & "',#" & request.form("courseday") &"/" & request.form("coursemonth") &"/"&request.form("courseyear")&"#)"
Conn.execute(SQL)
Conn.close
response.redirect("courseinserted.html")
%>

mattglet

1:09 am on Mar 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do a

response.write(SQL)
response.end

This will show your SQL statement, and you'll be able to check the format of the string, and see if any quirky things are happening.

-Matt

mattglet

1:11 am on Mar 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think this is your problem anyway:

SQL = "insert into course (Coursename,CourseLocation,CourseDate) values ('" & request("CourseName") & "','" & request("CourseLocation") & "', " # & request.form("courseday") &"/" & request.form("coursemonth") &"/"&request.form("courseyear")& # ")"

The # goes on the inside of the quote, not the outside.

-Matt