• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 145
  • Last Modified:

How do I Insert the Date from a form to an Access Database

This one is easy I know.  But I have users inserting info in a form.  When they click submit I would like the form to also submit the date in which they submitted.  I know this has to be in a hidden field because I don't want them to see it.  I need to know what i need to do to do this.  Also, what kind of field does it have to be in the access database? ie. text, date?
0
ibtaya
Asked:
ibtaya
1 Solution
 
Ryan ChongCommented:
>>I know this has to be in a hidden field because I don't want them to see it.
Try grab the server date on ASP and insert the date to your Access database on ASP, like:

If you want include time as well, else try:

...
SQLStr = "Insert into mytable (field1, fieldN, insertDate) values ('" & field1 & "', " & fieldN & ", Now()) "
conn.execute SQLstr
...

else try:

...
SQLStr = "Insert into mytable (field1, fieldN, insertDate) values ('" & field1 & "', " & fieldN & ", Date()) "
conn.execute SQLstr
...

>>what kind of field does it have to be in the access database
Try Date/Time data type.
0
 
ibtayaAuthor Commented:
Where would this code go?  I'm kinda new at this.  Would it go in the value box for the hidden field?
0
 
Ryan ChongCommented:
>>Where would this code go?
In your form's submission process page, like if your form tag looks like below:

<form name="form1" method="post" action="process.asp" onSubmit="validate(this)">

The form's submission process page will be as "process.asp"

>>Would it go in the value box for the hidden field?
To store the date value into form's hidden field is a bad design/ idea. As you can't aspect when the user eventually do the submission, it can be 1 minute after, 1 hour after, even maybe... Furthermore anyone also can create a similar form, and put their data they want in the hidden field, and then do the submission. That's means it give a "Door" to those hacker that can intrude to your server.. So, try to avoid to put data on hidden field, while it can be done on backend process.

regards
0
 
Mark GilbertSenior Performance EngineerCommented:
Hi there,

if you are going to use a database, why not consider having a timestamp field on the table.  This will then enable the user to submit data using a form to the database, and the database will do all the work of calculating the exact date and time that the submission was created.
0
 
triserosCommented:
I would go with inqwa's suggestion - set your DB field to date/time and in the default value field (at the bottom of teh design view) add the text,  Now() ,  this will create a date/timestamp for each new record added.

That way you don't need to use insert anything for the date/time as the DB will do it for you - just make sure to remove your hidden field from the form.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now