Forums

This topic is locked

Insert date into msaccess DB via ASPjscript

Posted 24 Oct 2006 22:11:37
1
has voted
24 Oct 2006 22:11:37 joel gerardi posted:
I am trying to enter the current date into my MSaccess DB when a form is submitted. I also want to be able to do the same when the form is updated. I can get the date to display Day mm/dd/yyyy time. The trouble is i dont want all of this information. Can anyone tell me how to format the date so all that is entered is MM/DD/YY? I am using a hidden field.

Using a default date in the DB itself doesnt work because an new record is created and stays empty until data is entered for it.

Replies

Replied 27 Oct 2006 16:57:48
27 Oct 2006 16:57:48 Dan Berdusco replied:
Create a hidden form field with the default value of <pre id=code><font face=courier size=2 id=code>&lt;%=Date()%&gt; </font id=code></pre id=code> and submit it with the form to the database. Then, when you would like to display the date from the database on your page, dislay it in the format of mm/dd/yy by double clicking the item in the server behaviour panel and applying the proper format.

Edited by - flexman44 on 27 Oct 2006 16:58:35
Replied 27 Oct 2006 17:28:30
27 Oct 2006 17:28:30 joel gerardi replied:
That wont give me the format that I need. That places the day, the date and the time. I need to find a way to insert only the date. (MM/DD/YY)
Replied 28 Oct 2006 04:58:24
28 Oct 2006 04:58:24 Dan Berdusco replied:
What are you doing with the data from the database? Are you displaying it on a webpage? Or is it stored only in a database. As far as I know, if you want the data format different in the database, then you would change the format directly in MS access. If you are displaying the data on a web page, then it doesn't matter the format in the database, you can choose to display the date in whatever format you like.
Replied 11 Dec 2006 23:27:58
11 Dec 2006 23:27:58 Andrew Ramsey replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
I am trying to enter the current date into my MSaccess DB when a form is submitted. I also want to be able to do the same when the form is updated. I can get the date to display Day mm/dd/yyyy time. The trouble is i dont want all of this information. Can anyone tell me how to format the date so all that is entered is MM/DD/YY? I am using a hidden field.

Using a default date in the DB itself doesnt work because an new record is created and stays empty until data is entered for it.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 11 Dec 2006 23:51:40
11 Dec 2006 23:51:40 Andrew Ramsey replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Sorry, my last submittal was applied incorrectly (it was my first ever). Please help. I have followed the above advice regarding adding &lt;%=DATA()%&gt; to my hidden field, but I get an "Object Expected" error. I can't figure out how to get past this error. My programming is date intensive and I need to be able to use this functionality. Any suggestions or guidancence for me?
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 12 Dec 2006 00:00:21
12 Dec 2006 00:00:21 Dan Berdusco replied:
Are you adding <pre id=code><font face=courier size=2 id=code> &lt;%=DATA()%&gt;</font id=code></pre id=code> or <pre id=code><font face=courier size=2 id=code> &lt;%=DATE()%&gt;</font id=code></pre id=code>?
Replied 12 Dec 2006 16:51:02
12 Dec 2006 16:51:02 Andrew Ramsey replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Trevor, thank you for responding. I was concerned that you may no longer be there.

I am adding &lt;%=DATE()%&gt;. At times I would simply copy/paste it just to insure I wasn't typing it incorrectly.

Interestingly, it worked the first time (when I read your note) before I left work one day but then never again after that.

I created a stripped-down test asp page that does not work.

The error I get is this:

Error Type:
Microsoft JScript runtime (0x800A138F)
Object expected
/Testing Folder/Test.asp, line 11

Here is a code.

&lt;%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form id="form1" name="form1" method="post" action="../Default.asp"&gt;
&lt;input name="Date" type="hidden" id="Date" value="&lt;%=date( )%&gt;" /&gt;
&lt;label&gt;
&lt;input type="text" name="textfield" /&gt;
&lt;/label&gt;
&lt;label&gt;
&lt;input type="submit" name="Submit" value="Submit" /&gt;
&lt;/label&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;


Any ideas?
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 12 Dec 2006 18:49:59
12 Dec 2006 18:49:59 Dan Berdusco replied:
It seems to have something to do with the fact that you are working with ASP JavaScript - I always work in ASP VBScript.

Although I am sure there are Several other "more correct" ways to accomplish this, i figured out a "work-around". Here's the code:

<pre id=code><font face=courier size=2 id=code> &lt;%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;% VarDate = Date() %&gt;
&lt;form id="form1" name="form1" method="post" action="../Default.asp"&gt;
&lt;input name="Date" type="hidden" id="Date" value="&lt;%=VarDate %&gt;" /&gt;
&lt;label&gt;
&lt;input type="text" name="textfield" /&gt;
&lt;/label&gt;
&lt;label&gt;
&lt;input type="submit" name="Submit" value="Submit" /&gt;
&lt;/label&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

</font id=code></pre id=code>

Hope that helps.

The other option would be to set the default value of the date field in the database to todays date (assuming that you are sending the data from the form to a database).

-Trevor


Edited by - flexman44 on 12 Dec 2006 19:18:49
Replied 13 Dec 2006 17:20:14
13 Dec 2006 17:20:14 Andrew Ramsey replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>

Trevor, you are awesome. Thank you for helping. I originally seeked advice on whether to use JavaScript of VBScript and ended up going with JScript. Because of this example that you helped me with, I was unimpressed with JavaScript and switched to VBScript and recreated my pages. Now I find that VBScript doesn't do something that JavaScript did easily. How do you insert more than one record from a page. I am getting a renaming error with VBScript but didn't with JScript.

Geez!!! If you have a suggestion, I'd appreciate it. Also, can you recommend a free upload file manager?

Thanks bud.


<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Reply to this topic