Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2010
    Posts
    14

    Unanswered: error on inserting value to the table

    anyone can tell me what's wrong with this code? it keeps on giving me error "Number of query values and destination fields are not the same".. please help..
    or if you have a better code than this, please help..

    btw, cTime and ccDate are Textbox

    Dim sql, in_sql, out_sql As String
    sql = "INSERT INTO Transaction(TimeIn , EntryDate) VALUES ('"
    sql = sql & cTime & "," & ccDate & "')"
    DoCmd****nSQL (sql)

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    In any case you cannot enclose the whole VALUE section in single quotes ('), it should be:
    Code:
    sql = "INSERT INTO Transaction(TimeIn , EntryDate) VALUES (" 
    sql = sql & cTime & "," & ccDate & ")"
    or
    Code:
    sql = "INSERT INTO Transaction(TimeIn , EntryDate) VALUES ('" 
    sql = sql & cTime & "','" & ccDate & "')"
    depending of the data type of both columns and their counterpart variables.

    Moreover, if TimeIn and EntryDate are of type Date/Time the corresponding variables must be enclosed in pound sign (#). Try:
    Code:
    sql = sql & "#" & cTime & "#,#" & ccDate & "#)"
    Have a nice day!

  3. #3
    Join Date
    Aug 2010
    Posts
    14
    the 3rd code works like charm! thanks!

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

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