UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

> Working On An Sql Insert / Update Combined, Office 2010    
 
   
robsworld78
post Feb 24 2012, 01:41 AM
Post #1

New Member
Posts: 19



Hi, I have a bit of an issue with SQL Update / Insert.

I have a form that runs an SQL insert when a field is popluated and it works fine. When this sql insert runs it can add anywhere from 1 new record to 50 new records depending whats on the form.

CODE
DoCmd.RunSQL "INSERT INTO Inventory (Product, OrderID, BarsLeftTemp, BarsGiven) " & _
"SELECT ProductID, " & [Forms]![CreateOrders]![OrdersOrdersSubform]![OrderID] & " AS OrderID, " & "BarsLeft, " & "BarsLeft " & _
"FROM VendorInventoryLevel " & _ "WHERE (BarsLeft>0 Or BarsLeft<0) AND VendorID=" & [Forms]![CreateOrders]![VendorID] & ";"


The insert is for details pertaining to an order. Now I have a button on the same form and when clicked I want it to run another SQL insert/update but don't know how to right the code.

The 2nd insert will contain exisiting records from the 1st insert as well as new records so it needs to update the existing and insert the new records, I can't have duplicates.

Example:

I start a new order and the 1st SQL insert runs and I get the following items.

Order# 235 (stored in orders table)

item1 - 10 (stored in ordersdetail table linked with orderID) (10 being quanity)
item2 - 10
item3 - 10
item4 - 10

Now when I press the button, if I have SQL insert like above it would do the following, if the quantity was 5 on these items. (it duplicates items)

item1 - 10
item1 - 05
item2 - 10
item3 - 10
item3 - 05
item4 - 10
item4 - 05
item5 - 05

and if i press the button with SQL update it does the following (only updates, didn't add item5)

item1 - 10, 05
item2 - 10,
item3 - 10, 05
item4 - 10, 05

I hope this makes sense in the end the final list should be as follows because it updated the items already on the order and inserted items not on the order, in this case being item5.

item1 - 10, 05
item2 - 10,
item3 - 10, 05
item4 - 10, 05
item5 - 05
Go to the top of the page
 
+

Posts in this topic
- robsworld78   Working On An Sql Insert / Update Combined   Feb 24 2012, 01:41 AM
- - the_captain_slog   you need to run 2 queries 1 insert new records ...   Feb 24 2012, 03:47 AM
- - pere_de_chipstick   Hi Would like to understand your scenario better...   Feb 24 2012, 03:55 AM
- - robsworld78   I think I know what you mean, but now I can't ...   Feb 24 2012, 04:04 AM
- - robsworld78   QUOTE (pere_de_chipstick @ Feb 24 2012, 04...   Feb 24 2012, 04:06 AM
- - robsworld78   On this update query, now I have it so if I click ...   Feb 24 2012, 04:21 AM
- - pere_de_chipstick   Hi Unless you have a real need for it then the us...   Feb 24 2012, 04:26 AM
- - datAdrenaline   Even though I take a very small hit on efficiency,...   Feb 24 2012, 01:48 PM
- - robsworld78   thanks for the replies, hth I do need to store bot...   Feb 24 2012, 04:31 PM
- - robsworld78   any ideas from anyone?   Feb 26 2012, 08:13 PM
- - datAdrenaline   Can you post your db with fake data in it? ... It ...   Feb 26 2012, 08:14 PM
- - robsworld78   Well, I'm happy I figured it out. Not the clea...   Feb 26 2012, 10:06 PM
- - MadPiet   <snip>When I hit the button it only updates ...   Feb 26 2012, 10:36 PM
- - datAdrenaline   Without seeing more details of how you have things...   Feb 27 2012, 01:35 AM
- - robsworld78   Thanks MadPiet for trying, datAdrenaline did nail ...   Feb 27 2012, 08:51 PM
- - robsworld78   ok, actually I was wrong, I knew it was to good to...   Feb 27 2012, 10:37 PM
- - datAdrenaline   This .... Set rstTransfer = Forms!CreateOrder...   Feb 28 2012, 11:18 AM
- - robsworld78   I changed that and the code runs now without error...   Feb 28 2012, 05:21 PM
- - datAdrenaline   Ok ... its good the have the Option Explicit and s...   Feb 28 2012, 10:34 PM
- - robsworld78   The recordsource for VansSetForTransfer is a query...   Feb 28 2012, 11:00 PM
- - datAdrenaline   Ok ... then the updated block of code (the 2nd blo...   Feb 28 2012, 11:30 PM
- - robsworld78   The 2nd bock of code does nothing, just runs error...   Feb 29 2012, 01:19 AM
- - datAdrenaline   >> it says FROM InventoryLevelVansSetForTra...   Feb 29 2012, 07:31 AM
- - robsworld78   Ok, I'll send you the db, thanks for offering...   Feb 29 2012, 09:14 PM


Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 20th May 2013 - 05:25 PM