Results 1 to 4 of 4
  1. #1
    zipaway is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    53

    Insert Data from one table to another Query

    Hello, using VBA I would like to select entries in a table where a certain criteria is met.
    Those selected entries would then be inserted into another table but not all of the columns, only a select few.

    I have created the following code below but it is giving me an error when it runs the SQL (Syntax Error (missing operator) in query expression 'Sched_Delivery_DateFROM ShipDeliveryDates Where Project_Number =100'.

    Dim pnumber As Integer
    Dim cnumber As Integer
    cnumber = DMax("Change_Number", "Change_Orders") + 1
    pnumber = Text198.Value

    Dim SQL2 As String



    SQL2 = "INSERT INTO Change_Orders_Dates ([Change_Number], [Project Number], [ShipmentNumber], [Current_Sched_Delivery_Date], [Current_Sched_Ship_Date])" & _
    "SELECT " & cnumber & ", " & pnumber & ", ShipmentNumber, Sched_Ship_Date, Sched_Delivery_Date" & _
    "FROM ShipDeliveryDates WHERE Project_Number =" & pnumber & ""

    DoCmd.RunSQL SQL2


    Tables

    ShipDeliveryDates Change_Orders_Dates Change_Orders
    Project_Number Change_Number Change_Number
    ShipmentNumber Project_Number Project_Number
    Sched_Ship_Date ShipmentNumber
    Sched_Delivery_Date Current_Sched_Ship_Date
    Current_Sched_Delivery_Date
    New_Sched_Ship_Date
    New_Sched_Delivery_Date

    Please let me know what I'm doing wrong, any help would greatly be appreciated.

  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
    Here's a very commonly used debugging technique:

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

    For starters, watch out for spaces between lines.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    zipaway is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    53
    Quote Originally Posted by pbaldy View Post
    Here's a very commonly used debugging technique:

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

    For starters, watch out for spaces between lines.
    Thank you so much for the tip! I figured out I need an extra space at the end of the first two lines of SQL.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    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. INSERT query: insert new data only
    By drh in forum Access
    Replies: 2
    Last Post: 04-04-2014, 05:31 PM
  2. Insert Into Query With Table data and values
    By WickidWe in forum Queries
    Replies: 1
    Last Post: 01-05-2014, 06:41 PM
  3. Replies: 1
    Last Post: 10-02-2013, 01:14 AM
  4. Replies: 25
    Last Post: 01-29-2013, 08:49 AM
  5. Replies: 1
    Last Post: 12-28-2010, 11:24 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