Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2002
    Location
    Hartford, CT
    Posts
    106

    Unanswered: Inserting through a form

    Hi,

    I have this piece of code to insert some data from some text fields on a form.

    sql = ("INSERT INTO [Custom_Detail$Product](Custom_Detail_id, Product_ID, Product_Count) VALUES (lCustom_Id, lProduct_Id, lCount);")
    DoCmd.RunSQL sql

    I am getting a syntax error on the INSERT INTO clause.

    Please help, I can't see what is wrong with it.

    Thanks a lot.
    Mo

  2. #2
    Join Date
    Jun 2002
    Location
    Vienna, VA
    Posts
    53
    The sql should be:

    sql = "INSERT INTO [Custom_Detail$Product](Custom_Detail_id, Product_ID, Product_Count) VALUES (" & me.lCustom_Id & "," & me.Product_Id & "," & lCount & ");")
    DoCmd.RunSQL sql

    You have to explicitly pass the values from the form to the sql statement, not the form references.

    Hope this helps!

    Leah

  3. #3
    Join Date
    Sep 2002
    Location
    Land of OZ
    Posts
    173

    Re: Inserting through a form

    Originally posted by mkasem
    Hi,

    I have this piece of code to insert some data from some text fields on a form.

    sql = ("INSERT INTO [Custom_Detail$Product](Custom_Detail_id, Product_ID, Product_Count) VALUES (lCustom_Id, lProduct_Id, lCount);")
    DoCmd.RunSQL sql

    I am getting a syntax error on the INSERT INTO clause.

    Please help, I can't see what is wrong with it.

    Thanks a lot.
    Are the data types of the fields being inserted into numerical? I built a table with exactly the same fields as yours and a form with the same fields as yours and copies your code and ran it and it worked fine.

    Perhaps a snap shot of the table fields might give me more of an idea.
    Cheers
    Mona
    ________________________________
    Life is too short to be sane or sensible. Weird people rule and normal people suck

  4. #4
    Join Date
    Oct 2002
    Location
    Hartford, CT
    Posts
    106
    Thanks a lot,

    Leah's idea worked.
    Mo

Posting Permissions

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