Adding dates to a database
-
I'm trying to create a forums site, and I would like to add a date to all posts. At the moment I have the following code: SQLStmt = "INSERT INTO Messages (ForumID, ParentID, PosterID, Title, Body, Date) " SQLStmt = SQLStmt & " VALUES (" & forumID & ", " & parentID & ", " & userID & ", '" & subject & "', '" & message & "', #" & Date() & "#)" set RS = conn.Execute(SQLStmt) Which when expanded prints something like: INSERT INTO Messages (ForumID, ParentID, PosterID, Title, Body, Date) VALUES (22, 0, 1, 'Test', 'Test Text', #2/14/2002#) This all works fine if I exclude the Date Field. The most descriptive error I get is: Microsoft JET Database Engine (0x80040E14) Syntax error in INSERT INTO statement. Any help would be greatly appreciated - X
-
I'm trying to create a forums site, and I would like to add a date to all posts. At the moment I have the following code: SQLStmt = "INSERT INTO Messages (ForumID, ParentID, PosterID, Title, Body, Date) " SQLStmt = SQLStmt & " VALUES (" & forumID & ", " & parentID & ", " & userID & ", '" & subject & "', '" & message & "', #" & Date() & "#)" set RS = conn.Execute(SQLStmt) Which when expanded prints something like: INSERT INTO Messages (ForumID, ParentID, PosterID, Title, Body, Date) VALUES (22, 0, 1, 'Test', 'Test Text', #2/14/2002#) This all works fine if I exclude the Date Field. The most descriptive error I get is: Microsoft JET Database Engine (0x80040E14) Syntax error in INSERT INTO statement. Any help would be greatly appreciated - X
I think you need to replace # signs with '. For example: INSERT INTO Messages (ForumID, ParentID, PosterID, Title, Body, Date) VALUES (22, 0, 1, 'Test', 'Test Text', '2/14/2002')
-
I think you need to replace # signs with '. For example: INSERT INTO Messages (ForumID, ParentID, PosterID, Title, Body, Date) VALUES (22, 0, 1, 'Test', 'Test Text', '2/14/2002')
I'm afraid that didn't work. But, Alas! I found the solution! I changed the 'Date' field to 'DatePosted'. I presume 'Date' is a reserved word. It took me three hours to figure that out. Oh well. Thanks for you help anyway - X
-
I'm afraid that didn't work. But, Alas! I found the solution! I changed the 'Date' field to 'DatePosted'. I presume 'Date' is a reserved word. It took me three hours to figure that out. Oh well. Thanks for you help anyway - X