Results 1 to 7 of 7
  1. #1
    chris.williams is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    94

    Help with SQL INSERT commands

    I have a form which is linked to table_1. When the form is processed via a command button, I want to take value_1 and value_2 of table_1 and insert them to value_1 and value_2 of table_2.

    The tables are not linked, and have no relation at all.



    I am having problems with the SQL syntax - any help would be appreciated.

    Code:
    DoCmd.RunSQL (INSERT INTO table_2 (value_1,value_2) VALUES value_1,value_2)

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    DoCmd.RunSQL "INSERT INTO table_2 (Field_1,Field_2) VALUES (value_1,value_2)"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    chris.williams is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    94
    Thanks - I tried that as well as this:

    DoCmd.RunSQL "(INSERT INTO tbl_IssuedCertificates (CertNumber,DesignConsultant) VALUES " & Me.CertNumber & "," & Me.DesignConsultant & ")"

    and I still get syntax errors.

  4. #4
    chris.williams is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    94
    This too didn't work:

    DoCmd.RunSQL "(INSERT INTO tbl_IssuedCertificates (CertNumber,DesignConsultant) VALUES (" & Me.CertNumber & "," & Me.DesignConsultant & ")"

  5. #5
    chris.williams is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    94
    It's the afternoon. My eyes are tiered. I have found the syntax errors and have gotten working. Thanks Paul.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Well, you missed the opening parentheses for the VALUES clause on the first. You have an extra opening parentheses at the beginning of both that I didn't have, and that shouldn't be there. You need delimiters if any field is text. This should help debug the SQL:

    http://www.baldyweb.com/ImmediateWindow.htm

    And this will help with the delimiters either field is text:

    http://www.baldyweb.com/BuildSQL.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Oops, posting at the same time. Glad you got it sorted out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. clarification with transfer commands
    By mike02 in forum Access
    Replies: 7
    Last Post: 08-08-2012, 09:37 AM
  2. Button Commands
    By JayX in forum Access
    Replies: 13
    Last Post: 12-09-2011, 05:37 PM
  3. If __ Then __ type commands in queries?
    By TUPJK in forum Access
    Replies: 7
    Last Post: 06-20-2011, 01:28 PM
  4. Basic commands in Access 2007
    By johnkl49 in forum Access
    Replies: 2
    Last Post: 09-23-2010, 04:07 PM
  5. Replies: 0
    Last Post: 09-08-2009, 11:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums