Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 11th, 2003, 01:29 AM
Authorized User
 
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default insert date (javascript) into access


I'm having trouble getting a date into access that has been "recorded" at the time a user fills out a form, below is my javascript, and then below that is a hidden field that holds the javascript variable.. and then an asp page that collects the date..

<SCRIPT LANGUAGE="JavaScript">
var month = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var nowDate = new Date();
 nowDate = nowDate.getDate() + " " + month[nowDate.getMonth()] + " " + nowDate.getFullYear();
var nowDatevar = document.write (nowDate);
</script>


Below is my form input that I thought would work to pass the date to access:

<input type=hidden name="datePosted" value= <% nowDatevar %> >


then on my asp page I have the below script to add the date to the access database..:
strInsert = strInsert & ",datePosted"
    strValues = strValues & ",'" & _
            Cstr(Request.Form("datePosted")) & "'"

any help would be great!
thanks
 
Old October 11th, 2003, 09:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

You don't need the hidden field to hold the date value. Just place it directly into the database with an insert statement on your .asp page like:

<%@ LANGUAGE = JavaScript%>
<%
   var month = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul",
      "Aug","Sep","Oct","Nov","Dec");
   var nowDate = new Date();
   var nowDate = nowDate.getDate() + " " + month[nowDate.getMonth()] + " " +
      nowDate.getFullYear();
   var orderNo;

   // Connect to database
   var adoConnection = Server.CreateObject("ADODB.Connection");
   adoConnection.Open("DSN=MySystemDSN");
   var adoRecordset;

   // Create SQL to insert new order with date value
   var mySQL = "INSERT INTO CustomerOrder " +
      "(CustomerName, CustomerAddress, TelNumber, OrderDate)";
   mySQL = mySQL + " VALUES ('" + Request.Form("txtCustomerName") + "','";
   mySQL = mySQL + Request.Form("txtCustomerAddress") + "','";
   mySQL = mySQL + Request.Form("txtTelNumber") + "','";
   mySQL = mySQL + nowDate + "')";

   // Execute SQL to add new order
   adoConnection.Execute(mySQL);

   // Create SQL to get autonumber generated OrderNo from CustomerOrder table
   // for order just added
   mySQL = "SELECT Max(OrderNo) AS MaxOrderNo FROM CustomerOrder WHERE ";
   mySQL = mySQL + " OrderDate = #" + nowDate + "# AND ";
   mySQL = mySQL + " CustomerName = '" + Request.Form("txtCustomerName") + "'";

   // Populate recordset with SQL to get OrderNo
   adoRecordset = adoConnection.Execute(mySQL);

   orderNo = adoRecordset("MaxOrderNo").Value;

   // Recordset not needed after this so close it and allow release of memory
   adoRecordset.Close();
   adoRecordset = null;

 HTH,

Bob








Similar Threads
Thread Thread Starter Forum Replies Last Post
insert current date vsempoux XSLT 10 July 11th, 2008 07:31 AM
Date Insert prasanta2expert ASP.NET 1.0 and 1.1 Basics 0 January 25th, 2007 04:22 AM
trigger to insert current date on insert kev_79 SQL Server 2000 3 January 23rd, 2006 05:58 PM
insert system date. no date and time jimmy Access VBA 6 November 20th, 2003 01:11 PM
Recordset date insert in access kev_79 Access ASP 3 June 5th, 2003 12:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.