Insert date value into Access DB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mclueless
    New Member
    • Jan 2008
    • 56

    Insert date value into Access DB

    I am really pissed with this date problem. please help me out.....

    [CODE=vb]Public rs As New ADODB.Recordset
    Private Sub Command1_Click( )

    Call connection
    Set rs = New ADODB.Recordset
    rs.Open "INSERT INTO DateTry(Date,Na me) VALUES('" & Text1.Text & "','" & Text2.Text & "')", con, 3, 3
    con.Close

    End Sub[/CODE]
    Plzzzzzzzzzzzzz Help!!!!!!!!!!!
    Last edited by Killer42; Feb 18 '08, 09:47 PM.
  • mclueless
    New Member
    • Jan 2008
    • 56

    #2
    It gives SYNTAX ERROR IN INSERT INTO STATEMENT error.....

    Comment

    • QVeen72
      Recognized Expert Top Contributor
      • Oct 2006
      • 1445

      #3
      Hi,

      What is your Database....?

      REgards
      Veena

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        Why you are using INSERT INTO while opening a record set ?
        Last edited by Killer42; Feb 18 '08, 09:52 PM. Reason: Corrected "INSER"

        Comment

        • lotus18
          Contributor
          • Nov 2007
          • 865

          #5
          Hi

          You cannot make Date as your field name. And if you want to insert date, it should be enclosed it with #.
          [code=vb]
          Public rs As New ADODB.Recordset
          Private Sub Command1_Click( )

          Call connection
          Set rs = New ADODB.Recordset
          rs.Open "INSERT INTO DateTry ([MyDate],[Name]) VALUES(#" & Text1.Text & "#,'" & Text2.Text & "')", con, 3, 3
          con.Close
          [/code]

          Rey Sean
          .
          Last edited by lotus18; Feb 15 '08, 01:25 PM. Reason: vb code tag added

          Comment

          • mclueless
            New Member
            • Jan 2008
            • 56

            #6
            I am using access....

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Possibly you can use Date as a field name, I'm not sure. But it's a really bad idea.

              As lotus18 pointed out, you need to use # delimiters around the date value in your SQL string. What he didn't mention is that the value must be in American format - that is, mm/dd/yyyy. You might be able to get away with using a different format, as long as there's no way the day and month can be confused - for example #01-Feb-2008#. If you try to use dd/mm/yyyy format, it will only work when the day is higher than 12 so Access can't mix up the day and month.

              I think debasisdas also raised a valid concern.

              Comment

              Working...