Results 1 to 3 of 3
  1. #1
    surajparmar is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    2

    Insert & then Delete

    Hi Everyone,

    I have a query where I am inserting records from one table to another. I would then like to delete the original records from the other table. To perform this I currently have 2 queries but this then requires the user to input the package reference twice. I am running both queries from a button within my form.

    Below is the SQL for the insert query:

    INSERT INTO OrderSerialInfo ( OrderNo, SerialInfo, PackageRef )
    SELECT DISTINCT (Orders.OrderNo), (StockSerialInfo.SerialInfo), (StockSerialInfo.PackageRef)
    FROM Orders, StockSerialInfo, Stock
    WHERE Orders.OrderNo=[Please enter OrderNo] And StockSerialInfo.PackageRef=[Please enter Package Reference];

    Once this is complete the button then runs the second query to delete the original records:
    DELETE *
    FROM StockSerialInfo


    WHERE PackageRef=[Please Re-enter PKG number];

    My question is how do I combine these 2 queries so that the user only needs to enter the package reference once rather than twice? I'm hoping it's an easy one I've missed but not too sure.

    Many thanks for all your help in advance,

    Suraj

  2. #2
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,170
    Hi everyone,

    it's indeed an easy one: just put 2 unbound controls on the form, and let the user type the order and package reference there. Then in your queries you put the names of the control like Forms![name form]![name control] as selection criterium in stead of the parameters [Please enter OrderNo] or [Please enter Package Reference].

    greetings
    NG

  3. #3
    surajparmar is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    2
    Hi NG,

    Many thanks for your quick response. I have created an unbound form and textboxes and updated my query to the following:


    INSERT INTO OrderSerialInfo ( OrderNo, SerialInfo, PackageRef )
    SELECT DISTINCT (Orders.OrderNo), (StockSerialInfo.SerialInfo), (StockSerialInfo.PackageRef)
    FROM Orders, StockSerialInfo, Stock
    WHERE Orders.OrderNo=Forms![TransferStock]![txtOrderNo] And StockSerialInfo.PackageRef=Forms![TransferStock]![txtPKGRef];


    Once I enter the values on my form I click a button that runs the query but receive a popup box "Enter Parameter Value" which mentions the SQL parameter and a empty text box to type something in. After clicking OK I get a second popup for the second parameter. Is there a mistake in my SQL?

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 table
    By Mclaren in forum Programming
    Replies: 4
    Last Post: 05-02-2010, 11:28 PM
  3. SQL Insert into
    By jamin14 in forum Programming
    Replies: 15
    Last Post: 04-01-2010, 12:35 AM
  4. Just insert new data
    By watzmann in forum Access
    Replies: 1
    Last Post: 11-29-2009, 11:48 AM
  5. help with insert
    By jamie in forum Access
    Replies: 1
    Last Post: 11-16-2009, 06:02 AM

Tags for this Thread

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