Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Inserting Date into Access

    I'm having a problem inserting the date into access.
    My access field is formatted as mm/dd/yyyy.

    This is what I have in my asp page.

    Dim dtToday
    dtToday = Date()

    objRS.AddNew
    objRS("Date") = dtToday
    objRS.Update

    Then I get this error message.

    [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.

    Anybody know what i'm doing wrong.
    Thanks

  • #2
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    I don't see a table anywhere.

    <edit>
    And I can't remember, but maybe you should rename your field name of "Date" to something like UserDate or PollDate or D_Date.

    I think I had some type of problem like that before when I did that, Might be a totaly differnt story.
    </edit>

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can we see the insert statement? That seems to be the problem yet you didn't include that code.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    185
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think you need to use square brackets for the column name:

    objRS("[Date]") = dtToday

    because "Date" is a reserved word in Access SQL.

  • #5
    New Coder
    Join Date
    Jun 2002
    Location
    Pilipinas
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi, try . . .

    Dim dtToday
    dtToday = Date

    objRS.AddNew
    objRS("Date") = dtToday
    objRS.Update

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Posts
    344
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by ReyN
    hi, try . . .

    Dim dtToday
    dtToday = Date

    objRS.AddNew
    objRS("Date") = dtToday
    objRS.Update
    This should work - Date is a function, but never has any parameters in it, therefore, it doesn't need to have the () attached at the end...

    Also, what BrainJar said could also be true, try changing the column name to "theDate" or "CreationDate" or something...

    ~Quack

  • #7
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    L0L.

    This is basically all I had, when I put in the date into my db.
    SQL = "INSERT INTO table (tabledate) VALUES (" & Now() & ")"

    I don't see a problem with it, nor would you. But at odd time, it did the little screw up I had told you.

    I don't know why it happend. all it was, was a mistake for the day and month. And I fixed it by:
    Month(Now()) & "/" & Day(Now()) & "/" & Year(Now()) & " " & FormatDateTime(Now(), vbLongTime)

    And Whammy's idea:
    default value.

    I have my db's all set up to do it all 3 ways. So, if anyone of them messes up, and they are do the problem anyways, I'll post another topic.

    Whammy, if it's all right with you and everyone else, this topic can be locked. I think the problem is sovled...
    For Now()

  • #8
    New Coder
    Join Date
    Jun 2002
    Location
    Pilipinas
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if all you need is a date, use Date. if you need date and time, use Now.

    NOTE: Both do not use parentheses.

  • #9
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    I am a little edgy on what "parentheses" is, but I think I'll be fine for the mean part.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •