Results 1 to 7 of 7
  1. #1
    tcox's Avatar
    tcox is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Oct 2015
    Posts
    46

    Help with INSERT INTO

    I'm having trouble forming the syntax for an INSERT INTO statement.

    It pulls values from a form (Edit Order) and uses them to add a new item to a parts order.
    Code:
       Private Sub AR_EditOrder_Click()
    
    
     INSERT INTO T_Order_Details (Order_ID, [Thorne_ID], [Machine_ID], [Part_Set], [Initials]) 
        VALUES ([Form]![CBO_OrderNumSel], [Form]![CBO_AR_ThorneID], [CBO_AR_MachineID], [Form]![CBO_AR_PartSet], [Form]![TXT_AR_Initials])
    End Sub
    I'm a C++ guy and don't yet get how VBA wants its stuff wrapped.

    Thanks!
    -Tevis

  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,521
    Simplest for you is probably

    Code:
    Dim strSQL As String
    
    strSQL = "INSERT INTO..."
    
    DoCmd.RunSQL strSQL
    Using RunSQL should allow you to leave the form references inside the string, though they need to be fixed:

    Forms Refer to Form and Subform properties and controls
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Need form name in the parameter references. Try:

    CurrentDb.Execute "INSERT INTO T_Order_Details (Order_ID, [Thorne_ID], [Machine_ID], [Part_Set], [Initials]) VALUES ([Forms]![form name here]![CBO_OrderNumSel], [Forms]![form name here]![CBO_AR_ThorneID], [Forms]![form name here]![CBO_AR_MachineID], [Forms]![form name here]![CBO_AR_PartSet], [Forms]![form name here]![TXT_AR_Initials])"

    or if it doesn't like that, concatenate with Me alias. Which fields are text and which are number type? - maybe:

    CurrentDb.Execute "INSERT INTO T_Order_Details (Order_ID, [Thorne_ID], [Machine_ID], [Part_Set], [Initials]) VALUES (" & Me.CBO_OrderNumSel & ", " & Me.CBO_AR_ThorneID & ", " & Me.CBO_AR_MachineID & ", '" & Me.CBO_AR_PartSet & "', '" & Me.TXT_AR_Initials & "')"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    tcox's Avatar
    tcox is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Oct 2015
    Posts
    46
    ORDER_ID | Number
    Thorne_ID | Number
    Machine_ID | Short Text
    Part_Set | Short Text
    Initials | Short Text

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Okay, if you use the concatenation method, include apostrophe delimiters for parameters of text fields as shown in the example. I did not put them in the Machine_ID.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    tcox's Avatar
    tcox is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Oct 2015
    Posts
    46
    Wow! Thank you!

    I'll save this as an example for further work.

    -Tevis

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Date/time fields use # delimiter.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 3
    Last Post: 05-27-2015, 01:04 PM
  2. Insert into
    By sovereign in forum Forms
    Replies: 3
    Last Post: 05-08-2015, 07:28 AM
  3. INSERT query: insert new data only
    By drh in forum Access
    Replies: 2
    Last Post: 04-04-2014, 05:31 PM
  4. SQL Insert into
    By jamin14 in forum Programming
    Replies: 15
    Last Post: 04-01-2010, 12:35 AM
  5. help with insert
    By jamie in forum Access
    Replies: 1
    Last Post: 11-16-2009, 06:02 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