Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2005
    Posts
    61

    Unanswered: Insert statement receiving syntax error

    Hello,

    I am having a problem with an insert statement in Access with my vb code and I can not figure it out. I'm receiving an syntax error.

    here is the code:

    sqltxt = "INSERT INTO DummyDCNs (MailRoomUNumber, DocType, Group, MemberID, JulianYear, JulianDay, CameraNumber, DummyDCNNumber, DateCreated)"

    sqltxt = sqltxt + "VALUES('" & MailRoomUNumber.Value & "', '" & cmbDoctype.Value & "', '" & cmbGroup.Value & "', '" & txtMemberID.Value & "', '" & txtJulianYear.Value & "', '" & txtJulianDay.Value & "', '" & cmbCamera.Value & "', '" & txtDummyDCNNumber.Value & "', '" & DateCreated.Value & "');"


    Here is value of sqltxt before running.

    "INSERT INTO DummyDCNs (MailRoomUNumber, DocType, Group, MemberID, JulianYear, JulianDay, CameraNumber, DummyDCNNumber, DateCreated)VALUES('U111111, 'Route Sheet', '01TX', '123456789', '7', '001', '450', '1', '1/12/2007');"

    and when it runs I receive a syntax error.

    Any help would be greatly appreciated.

    Mythos

  2. #2
    Join Date
    Jan 2007
    Posts
    5
    At the end of the statement you dont put ; as VB doesnt like it.

    Change to:

    sqltxt = "INSERT INTO DummyDCNs (MailRoomUNumber, DocType, Group, MemberID, JulianYear, JulianDay, CameraNumber, DummyDCNNumber, DateCreated)VALUES('U111111, 'Route Sheet', '01TX', '123456789', '7', '001', '450', '1', '1/12/2007')"

  3. #3
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    I doubt the semi-colon is the problem. First of all, add a space between the closing parenthesis and the word "VALUES". Second, review the data types of your fields, keeping in mind that only text values need to be surrounded by single quotes. Date values need to be surrounded by "#", and numeric values shouldn't be surrounded by anything.
    Paul

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    fifth: the first "value" you're passing in doesn't have a closing single quote...
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

Posting Permissions

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